Groups

    Calling All Web Designing Type Programmer Type People!

    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!

    12 Comments

    Never done CGI... No tutorials around?

    does it actually have to be a cgi script?

    are you developing in any specific languages already like php or asp?

    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.

    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

    Are you using perl or php?

    Original Poster

    dcx_badass

    So you want someone else to do a pretty important part of your uni … 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 … 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 … 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.

    Original Poster

    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" 22nd Feb 2011

    Boom123

    Its mainly Perl but i do need to include CGI Scripts where necessary so … 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" 22nd Feb 2011

    Original Poster

    jennyrocks

    This sounds like something I did at uni but with a house system. So you … 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" 22nd Feb 2011



    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.


    You start a perl file as normal:

    importing the usual lines and DBI for sql support.

    #Get fields from form:


    #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


    #print data entered back to user:


    #print search results
    Boom123

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

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

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

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

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

    print "** House Requirements **";print " ";print "Price: $PRICE";print … print "** House Requirements **";print " ";print "Price: $PRICE";print "Bedroom: $BEDROOMS";

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

    $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($sth-rows0){print "table border=\"1\"< ";print "td Price td BedroomstdLocation if($sth->rows>0){print ">table border=\"1\"< ";print "td> Price td> Bedroomstd>Location td>Property Type Comments /tr>";

    while( @result = $sth-fetchrow_array){print " tr<>td< £ $result[0] td $result[1] td … while( @result = $sth->fetchrow_array){print " >tr<>td< £ $result[0] td> $result[1] td> $result[2] td> $result[3] td> $result[4] \n";}print "";}else{print "No Searches found/n";}

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


    Edited by: "jennyrocks" 22nd Feb 2011

    Original Poster

    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!!!

    Boom123

    Wow thats amazing dude,Can't thank you enough! You really do know your … 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 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
    Avatar
    @
      Text
      Top Discussions
      1. Veteran TV host Sir Bruce Forsyth dies at 892529
      2. Veteran TV presenter doesn't die but gets damages from the Police - is that…66
      3. Just heard this...2 ★★★★★★★★★★★★★★ congrats to all on 392k ★★★★★★★★★★★★★★7764306
      4. ❅☁☁❅ I want☼to talk☼about the☔WEATHER☔no politics☃no religion❅☁☁❅18846211

      See more discussions