GCI DataBase Program

Put Your Plan Into Action

GCI DataBase Program

CGI (common Getway interface) Program to insert data in xamp server database.

In this program we are taking two input which is name and age we are inserting these value into database.

#!"c:\xampp\perl\bin\perl.exe"
use CGI ':standard';
use DBI;
if(param)
{
print
header(),
start_html(-title=>"Web page to enter name and age",-bgcolor=>"yellow",-text=>"blue"),
"Enter name and age",
start_form(),
textfield('name'),
textfield('age'),
br(),br(),
submit();
$dbh=DBI->connect('DBI:mysql:studentdb',"root","")
or die "error connect:DBI->errstr()";
$name=param('name');
$age=param('age');
$qh=$dbh->prepare("insert into student values('$name','$age')")
or die "can't execute query:$dbh->errstr()";
$qh->execute();
$qh=$dbh->prepare("Select * from student");
$qh->execute();
print "<table border size=1><tr><th>Name</th><th>Age</th></tr>";
while ( ($name,$age)=$qh->fetchrow())
{
print "<tr><td>$name</td><td>$age</td></tr>";
}
print "</table>";
$qh->finish();
$dbh->disconnect();
print end_html();
}
else
{
print
header(),
start_html(-title=>"Web page to enter name and age",bgcolor=>"yellow",-text=>"blue"),
"Enter name and age",
start_form(-action=>"7.pl",-method=>"post"),
textfield(-name=>'name'),
textfield(-name=>'age'),
br(),br(),
submit();
end_form(),
end_html();
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *