CGI Programming and Scripts in Perl

EXAMPLE -1



type the following in terminal [linuxpert@localhost ~]$ su Password:
[root@localhost linuxpert]# cd /var/www/cgi-bin

[root@localhost cgi-bin]# gedit



type the following in gedit

#!/usr/bin/perl use CGI;
$cgi=new CGI;

print $cgi->header,

$cgi->start_html,

$cgi->h1("A simple Example"),

$cgi->end_html;



type  the following  in the same terminal

[root@localhost cgi-bin]# chmod +x form.cgi



go to browser and type the following URL





EXAMPLE -2



in terminal [linuxpert@localhost ~]$ su Password:
[root@localhost linuxpert]# cd /var/www/html

[root@localhost html]# gedit



type the following in gedit editor

<html>

<head>

<title>LOGIN</title></head>

<body>

<form action="/cgi-bin/form2.cgi" method="post">

<p>

"Enter student roll no"<input type="text" name="rollno"></p>

<p>"enter the student name"<input type="text" name="sname"></p>

<p>"click here to submit"<input type="submit" name="submit"></p>

</form>

</body>

save the page as form.html  & close it type the following URL in browser





then type the following in the terminal



[root@localhost html]# cd /var/www/cgi-bin

[root@localhost cgi-bin]# gedit



type the following in gedit


#!/usr/bin/perl use CGI;
$cgi=new CGI;
use DBI;
$rollno=$cgi->param('rollno');
$name=$cgi->param('sname');
my $dbh=DBI->connect("dbi:mysql:student","root","");
my $sth=$dbh->prepare("insert into students values(?,?)");
$res=$sth->execute($rollno,$name);
$dbh->disconnect;
if($res)
{
print $cgi->header,
$cgi->start_html,
$cgi->h1("Record created"),
$cgi->end_html;
}


save that file as form2.cgi
close that file & open a same terminal type as [root@localhostcgi-bin]# chmod +x form2.cgi In new browser type the following  

now check the database as


mysql> select * from students;
+--------+---------------+
| rollno | sname       |
+--------+---------------+
|   100 | thamarai    |


|   200 | selvi        |
|   NULL | abcd         |
|     71 | thamaraiselvi |
+--------+---------------+
4 rows in set (0.00 sec)


write a cgi program using html | how to create a cgi program in perl using html | cgi script | run cgi program | example for cgi program | cgi programming | cgi scripts | cgi programming with in perl language | cgi programming with c |cgi programming with perl | cgi internet programming c++ c | software cgi programming tools | cgi programming tools freeware | cgi programming support | downloads cgi programming tools | cgi scripts | cgi tutorial

0 comments:

Post a Comment