GIDForums  

Go Back   GIDForums > Webmaster Forums > Web Design Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Jul-2009, 09:00
hackYourBrain hackYourBrain is offline
New Member
 
Join Date: Jul 2009
Posts: 3
hackYourBrain is on a distinguished road

Need help with Perl cgi


Hi guys I have a lab to complete where I need to be able to access, pull and add data from a database. I wrote this scrip in perl but I dont know how to call functions using a button or an anchor tag for example. The mySQL statements work fine as I have tested them from command line. Can someone please tell me what the proper syntax is? as you can see I the only thing we have learned is how to use param(). Im refereing to the proper syntax in the startHtml() =>script and the buttons in the subHtmlForm().. I also dont know if its legal that im using cgi.pm and regular xhtml at the same time.. dont think it is. PLease helpP.. thanks in advanced. that is when i press the button once the page is generated nothing happens!!

HTML Code:
#!/usr/bin/perl use strict; use warnings; use CGI qw/:all/; use CGI::Pretty; use CGI::Carp "fatalsToBrowser"; use DBI; my $serverName=; my $serverPort=; my $serverUser=; my $serverPass=; my $serverDb=; my $serverTabl=; if(!param()){ htmlForm(); }else{ my $error=insert_entry(); show_entries($error); } sub htmlForm{ print header(); print start_html(-title=>'Lab 6',-scrip=>{-language=>'PerlScript', src=>'mySqlProg.cgi'}); print h1("Enter data in to mysql table(lab 6)"); print startform({-action=>"",-method=>"POST"}); print table(TR(td("First Name:"),td(textfield({-name=>"fname",-size=>"11",-maxlength=>"10"}))), TR(td("Last Name:"),td(textfield({-name=>"lname",-size=>"11",-maxlength=>"10"}))), TR(td("Student ID:"),td(textfield({-name=>"id",-size=>"10",-maxlength=>"9"}))), TR(td("Logins:"),td(textfield({-name=>"logins",-size=>"4",-maxlength=>"3"})))); print submit(-name=>'submit_form', -value=>'Submit form'); print end_form(); print "<button type='button' value='view' onclick='show_entries();'>Show Table Values</button>"; print "<button type='button' value='increment' onclick='increment();'>Increment logins by 1</button>"; print "<button type='button' value='change' onclick='change();'>Any field, change the # 6 to 4</button>"; print end_html(); } sub insert_entry { my ($dbh,$sth,$Fname,$Lname,$studentID,$Logins,$success); $dbh=DBI->connect("DBI:mysql:database=$serverDb;host=$serverName;port=$serverPort",$serverUser,$serverPass) or die ("Cant connect to the database: ". DBI->errstr); $Fname=param("fname"); $Lname=param("lname"); $studentID=param("id"); $Logins=param("logins"); $success=$dbh->do("INSERT INTO $serverTabl(firstname,lastname,SID,logins) VALUES(?,?,?,?)", undef,$Fname,$Lname,$studentID,$Logins); $dbh->disconnect; if($success != 1){return "Sorry, the database was unable to add your entry.";} } sub show_entries { my($dbh, $sth, @row); $dbh=DBI->connect("DBI:mysql:database=$serverDb;host=$serverName;port=$serverPort",$serverUser,$serverPass); $sth=$dbh->prepare("SELECT firstname,lastname,SID,logins FROM $serverTabl"); $sth->execute; print header(); print start_html(-title=>'Lab 6'); if($_){print "$_";} print "Existing Entries",hr; while(@row=$sth->fetchrow_array){ print "First Name: ", $row[0], br; print "Last Name: ", $row[1], br; print "Student ID: ", $row[2], br; print "Logins: ", $row[3], br,br; } print end_html(); $sth->finish; $dbh->disconnect; } sub increment{ my($dbh); $dbh=DBI->connect("DBI:mysql:database=$serverDb;host=$serverName;port=$serverPort",$serverUser,$serverPass); $dbh->do("UPDATE $serverTabl SET logins=logins+1"); $dbh->disconnect; } sub change{ my($dbh, $sth, @row); $dbh=DBI->connect("DBI:mysql:database=$serverDb;host=$serverName;port=$serverPort",$serverUser,$serverPass); $sth=$dbh->prepare("SELECT firstname,lastname,SID,logins FROM $serverTabl"); while(@row=$sth->fetchrow_array){ for(my $i=0;$i<=3;$i++){ if($row[$i]){ $row[$i]=~s/6/4/g; } } $dbh->do("UPDATE $serverTabl SET firstname=$row[0],lastname=$row[1],SID=$row[2],logins=$row[3] WHERE firstame=$row[0]"); } $sth->finish; $dbh->disconnect; }
  #2  
Old 30-Jul-2009, 08:44
hackYourBrain hackYourBrain is offline
New Member
 
Join Date: Jul 2009
Posts: 3
hackYourBrain is on a distinguished road

Re: Need help with Perl cgi


more specifically im refering this this
Quote:
print start_html(-title=>'Lab 6',-scrip=>{-language=>'PerlScript', src=>'mySqlProg.cgi'});

in relation to this onClick function call
Quote:
print "<button type='button' value='view' onclick='show_entries();'>Show Table Values</button>";

DAVE where are you buddy??

Thanks guys
Brain
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache runs multiple perl processes which take 100% CPU Boonstra Apache Web Server Forum 0 17-Apr-2009 14:31
PERL If/ else Statement problem Reny Miscellaneous Programming Forum 2 25-Jul-2007 00:20
Problem Runnig Perl under Apache2 in Windows 2000 Server mig2000 Apache Web Server Forum 2 25-Oct-2004 07:20
PERL instead of SSI for static data Griff Web Design Forum 4 24-Aug-2004 06:50
Apache perl version mismatch - can I fix it? chinagirl Apache Web Server Forum 1 25-May-2004 02:13

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:55.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.