Hi,
I am using two files sqlconfig.cgi and contactform.htm l, the former being the script that links to the html. However, when I run the html file from the browser it simply publishes the script instead of passing parameters.
Yes, I have configured Apache for CGI and gave write permissions to my files.
here are the codes:
1. sqlconfig.cgi
2. contactsform.ht ml
Can someone please check where is the error.
I am using two files sqlconfig.cgi and contactform.htm l, the former being the script that links to the html. However, when I run the html file from the browser it simply publishes the script instead of passing parameters.
Yes, I have configured Apache for CGI and gave write permissions to my files.
here are the codes:
1. sqlconfig.cgi
Code:
#!C:\Dwimperl\perl\bin\perl.exe # PERL MODULES WE WILL BE USING use CGI; use DBI; use DBD::mysql; # Config DB variables our $platform = "mysql"; our $database = "test"; our $host = "localhost"; our $port = "3306"; our $tablename = "addressbook"; our $user = "root"; our $pw = "password"; our $q = new CGI; # DATA SOURCE NAME $dsn = "dbi:mysql:$database:localhost:3306"; # PERL DBI CONNECT $connect = DBI->connect($dsn, $user, $pw); #Get the parameter from your html form. $lname=$q->param('lname'); $fname=$q->param('fname'); $phone=$q->param('phone'); $email=$q->param('email'); $address=$q->param('address'); $zip=$q->param('zip'); print $q->header; print "Hello $fname $lname"; $sql="INSERT INTO test.addressbook(last_name,first_name) values('$lname','$fname')"; $sth = $connect->prepare($sql) or die "Can't prepare $sql: $connect->errstrn"; #pass sql query to database handle.. $rv = $sth->execute or die "can't execute the query: $sth->errstrn"; #execute your query if ($rv==1){ print "Record has been successfully updated !!!"; }else{ print "Error!!while inserting recordn"; exit; }
Code:
<html> <head> <title>ADDRESS BOOK</title> </head> <body bgcolor="#FFFFFF" link="#0000FF" alink="#FF0000" vlink="#C000FF"> <h1>ADDRESS BOOK CONTACTS</h1> <table> <form method="get" action="C:/Apache/Apache2/cgi-bin/sqlconfig.cgi"> <tr> <td align="right">Last Name:</td> <td align="left"><input type="text" name="lname" size="15" maxlength="50"></td> <td align="right">First Name:</td> <td align="left"><input type="text" name="fname" size="15" maxlength="50"></td> </tr> <tr> <td align="right">Phone:</td> <td align="left"><input type="text" name="phone" size="15" maxlength="50"></td> <td align="right">Email:</td> <td align="left"><input type="text" name="email" size="15" maxlength="50"></td> </tr> <tr> <td align="right">Address:</td> <td align="left"><input type="text" name="address" size="15" maxlength="50"></td> <td align="right">Zip Code:</td> <td align="left"><input type="text" name="zip" size="15" maxlength="50"></td> </tr> </table> <input type="submit" value="Submit" onclick="addcontact"> </form> </body> </html>
Comment