Calling All Web Designing Type Programmer Type People! - HotUKDeals
We use cookie files to improve site functionality and personalisation. By continuing to use HUKD, you accept our cookie and privacy policy.
Get the HUKD app free at Google Play

Search Error

An error occurred when searching, please try again!

Login / Sign UpSubmit

Calling All Web Designing Type Programmer Type People!

Boom123 Avatar
5y, 9m agoPosted 5 years, 9 months ago
Right so um i've come across an issue.. I need this for an uni assignment but i can't seem to find the right people to ask

I'm making a website for an airline (not real obviously) but I have an sql database but i need to make some code in CGI script so that it can look up the database and give back results if they can book..

How do i link a button the button to search the script? how do i write the script lol (im useless at CGI)

someone please helppp me!
Boom123 Avatar
5y, 9m agoPosted 5 years, 9 months ago
Options

All Comments

(12) Jump to unreadPost a comment
Comments/page:
#1
Never done CGI... No tutorials around?
#2
does it actually have to be a cgi script?

are you developing in any specific languages already like php or asp?
#3
What language are you using for CGI scripting? An example is to use javascript to trap the button event. Upon trapping the button event, you can use more javascript (or possibly C# in an ASP.NET/C# environment) to read the contents of the HTML controls. For javascript, you need to use DOM access and for ASP.NET, it is easy as the .NET framework give you direct access to the controls. For PHP, you can also access contents of HTML controls.

For access to SQL database, PHP or C# with ODBC connections are typically used.
#4
If it's for SQL databases you are probably best using PHP - theres lots of resources online that will help you grab data from a database using php
#5
Are you using perl or php?
#6
dcx_badass
So you want someone else to do a pretty important part of your uni assignment, can you not ask lecturers for help?

Its not really that important tbh, i could blag it and make it look like it works by making another webpage lol but i'd rather it look and work right, I just need to find a way of returning data from a SQL database but can't seem to find anything..

ElliottC
What language are you using for CGI scripting? An example is to use javascript to trap the button event. Upon trapping the button event, you can use more javascript (or possibly C# in an ASP.NET/C# environment) to read the contents of the HTML controls. For javascript, you need to use DOM access and for ASP.NET, it is easy as the .NET framework give you direct access to the controls. For PHP, you can also access contents of HTML controls.

For access to SQL database, PHP or C# with ODBC connections are typically used.

Now thats the help i'm talking about! Found some PHP tutorials which should help, it is my fault, hardly been attending the lectures for this because their soooo boring...

Moofin
If it's for SQL databases you are probably best using PHP - theres lots of resources online that will help you grab data from a database using php

Thanks for that !! Will do some PHP tutorial research! :)


And thanks to everyone for their input too.
#7
jennyrocks
Are you using perl or php?


Its mainly Perl

but i do need to include CGI Scripts where necessary so i'm stumped on how this would work. I've been using Notepad++ but i'm going nowhere, i used dreamweaver to get my website to actually look good, but its written this out in HTML but now i need some CGI Script so that i can actually get it to look up data on a database but i can't find anything to help me

Thanks

Edited By: Boom123 on Feb 22, 2011 16:37
#8
Boom123
jennyrocks
Are you using perl or php?


Its mainly Perl

but i do need to include CGI Scripts where necessary so i'm stumped on how this would work. I've been using Notepad++ but i'm going nowhere, i used a bit of dreamweaver to get my website looks etc up to date, but i can't find anything to help me return data from a database!

Thanks


This sounds like something I did at uni but with a house system. So you have a form that has some options to search for a certain flight or going to a certain destination?

That form will then pass on the search details to the next part of the script which searches the database and displays it in table format?



Edited By: jennyrocks on Feb 22, 2011 17:05: ..
#9
jennyrocks
Boom123
jennyrocks
Are you using perl or php?


Its mainly Perl

but i do need to include CGI Scripts where necessary so i'm stumped on how this would work. I've been using Notepad++ but i'm going nowhere, i used a bit of dreamweaver to get my website looks etc up to date, but i can't find anything to help me return data from a database!

Thanks


This sounds like something I did at uni but with a house system. So you have a form that has some options to search for a certain flight or going to a certain destination?

That form will then pass on the search details to the next part of the script which searches the database and displays it in table format?




Yup spot on but with a chosen destination and date, I guess you have done this sorta thing before lol
Help help help!
Thank you!

Edited By: Boom123 on Feb 22, 2011 21:30
#10
Boom123

Yup spot on but with a chosen destination and date, I guess you have done this sorta thing before lol
Help help help!
Thank you!


Ok so you have your html file with the form setup right.
You need the html form to point to airline.pl or whatever your perl script is called.

So along the lines of >form method="get" action="house.pl"<


You start a perl file as normal:

#!/usr/bin/perl -w
use CGI':standard';
use CGI::Carp "fatalsToBrowser";
use warnings;
use DBI;

importing the usual lines and DBI for sql support.

#Get fields from form:

$PRICE=param('PRICE');
$BEDROOMS=param('BEDROOMS');


#Do some data validation (will probably pick up marks here) stuff like is destination the same as from list / is date past or present etc

if(($PRICE=~m/\d+/)&&($PRICE > 10000) && ($PRICE < 100000))
{
print "Price: is VALID input ALSO in price margin $PRICE
";
}
else
{
print "Price: is an invalid input $PRICE
";
exit;
}


#print data entered back to user:

print "
** House Requirements **

";
print "
";

print "Price: $PRICE
";
print "Bedroom: $BEDROOMS
";


#print search results

print "
Search Matches
";

#database query

$query=qq("SELECT * FROM houses");


#datebase login

$user="username";
$pass="password";
$dbh=DBI->connect('DBI:mysql:database=database;host=host',$user,$pass) or die "Can't connect to database";



$sth=$dbh->prepare($query);
$sth->execute;


#if rows returned

if($sth->rows>0)
{
print ">table border=\"1\"< ";
print "<tr<>td> Price

</td<>td> Bedrooms

</td<>td>Location

</td<>td>Property Type

</td<>td>Comments

</td<>/tr>";


#Important part is the while has records line.

while( @result = $sth->fetchrow_array){
print " >tr<>td< £ $result[0]

</td<>td> $result[1]

</td<>td> $result[2]

</td<>td> $result[3]

</td<>td> $result[4]
\n";
}
print "
";
}
else
{
print "No Searches found/n";}

#Make sure you close the connection at the end

$sth->finish;
$dbh->disconnect;



Edited By: jennyrocks on Feb 22, 2011 21:56
#11
Wow thats amazing dude,
Can't thank you enough! You really do know your stuff!
I'm meeting up with some of my team tomorrow so i'll see if we can get our script working.

I really cant thank you enough! especially the database login part! Exactly what i needed!

So so happy!! THANK YOU!!!
#12
Boom123
Wow thats amazing dude,
Can't thank you enough! You really do know your stuff!
I'm meeting up with some of my team tomorrow so i'll see if we can get our script working.

I really cant thank you enough! especially the database login part! Exactly what i needed!

So so happy!! THANK YOU!!!


No probs :D if you need anymore help give me a shout and I'll see what I can do.

Make sure you validate all data before putting it through the database too as you will get marks for that. I'm assuming that what they want by CGI scripts. Have a few more of them somewhere I can dig out tomorrow if you get stuck. The validate email one we had to do was probably the hardest. But as long as you show you can check a telephone number is only numbers and text matches other text you will be fine.

Post a Comment

You don't need an account to leave a comment. Just enter your email address. We'll keep it private.

...OR log in with your social account

...OR comment using your social account

Thanks for your comment! Keep it up!
We just need to have a quick look and it will be live soon.
The community is happy to hear your opinion! Keep contributing!