CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Getting a cgi (form) program to call a perl (database) program

 



chamberssh
Deleted

Sep 22, 2000, 8:50 AM

Post #1 of 1 (497 views)
Getting a cgi (form) program to call a perl (database) program Can't Post

Hi,
I have two standalone programs;
1) i can direct the url (cgi-bin) to a first perl prog (.cgi extension) which displays a text box prompting the user to enter their name. The user then fills in the text box and presses a submit button. Upon pressing the submit button this html form is sent to a second .cgi prog using the POST method, which generates and returns a new html page showing the value (name) that the user input.

2) I have written a perl program (.pl extension) to link to an Access db (using odbc) and inserts some dummy data.

Now both of these work ok on their own, but what i want/need is to link these two up so that whaever values are submitted by the form to the second cgi program are also entered into the database using the perl db program. This must be simple to link up, but i have spent ages trawling through and getting lost in loads of dcumentation on perl/cgi/IIS, surely this is a syntax and not system configuration problem as i can run the perl db from the command line and can navigate to the cgi program via windows explorer.

Please can someone help?

P.S. RELAVANT CODE:-
CGI SUBMIT PART;
#!/usr/local/bin/perl
use CGI;

$co = new CGI;
print $co->header,
$co->start_html
(),
print $co->header,
"Reasons for filling out our survey:",
$co->p,
$co->hr,
$co->start_form
(-method=>'GET',
-action=>"http://www.corus.co.uk/cgi-bin/cgi2.cgi"),
"Please enter your name: ",
$co->textfield('text'), $co->p,
$co->center
($co->submit('Submit'),
$co->reset,),
$co->hr,
$co->end_form,
$co->end_html;


PERL DB (.PL) FILE;
use win32::ODBC;
use DBI;
use CGI;
$co = new CGI;
print "\tOpening ODBC connection for \"rosgov\"...\n\t\t";
if (!($O = new Win32::ODBC("rosgov"))){
print "Failure. \n\n";
$Failed{'Rosgov.mdb'} = "new(): " . Win32::ODBC::Error();
PresentErrors();
exit();
}else{
print "Success (connection #", $O->Connection(), ")\n";

my $dbh =DBI->connect('DBI:ODBC:ROSGOV') | | die "cannot open the database";
if(defined($dbh)){print " a link to the db $O has been established\n"}

my $sth = $dbh->prepare( q{SELECT * from forms
}) | | die "Can't prepare statement: $DBI::errstr";
my $sth = $dbh->prepare( q{INSERT INTO forms(
yourname,
) VALUES
('name')})| |die "cannotinsert data";
my $result = $sth->execute();




 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives