Unable to pass parameters through 2 scripts - perl -
#!/usr/bin/perl -wt use dbi; use cgi qw(:standard); use digest::md5 qw(md5_hex); $db="int420_172a14"; $user="int420_172a14"; $passwd="ndww9855"; $host="db-mysql.zenit"; $connectioninfo="dbi:mysql:$db;$host"; $q = new cgi; $submit = param('submit'); @productid = $q->param('productid'); ($cookiename, $cookievalue) = split(/=/, $env{http_cookie}); if ($submit eq "purchase item") { print "content-type:text/html\n\n"; print qq~<html> <head><title>checkout page</title></head> <body background=/images/back.jpg> <center><a href=/cgi/stage5.cgi>click here return catalog</a></center> <center><a href=/>click here return main page</a></center> <p>@productid</p> ~; checkout(); } elsif ($submit eq "checkout") { &completecheckout(); } elsif ($env{http_cookie} =~ /username/) { print "content-type:text/html\n\n"; catalog(); } else { print "location:http://zenit.senecac.on.ca:20720/cgi/login.cgi\n\n" } sub catalog { $select = qq~select * catalog~; $dbh=dbi->connect($connectioninfo,$user,$passwd); $sth=$dbh->prepare($select); $sth->execute(); print qq~<html> <head><title>shopping catalog</title></head> <body background=/images/back.jpg> <center><h1>welcome our shopping catalog</h1> <h3>please select product below</h3></center> <center><a href=/>click here return main page</a></center> <p>$env{http_cookie}</p> <table border=2 align=center> <th>products</th> ~; $id = 1; while (@row=$sth->fetchrow_array()) { print qq~ <tr> <td height=100>$row[1]<br> $row[2]<br> \$$row[3]<br> <img src=/images/$row[4] height=100 width=100 alt="product image not found."> <form action="" method=post><input type=checkbox name=productid value="$row[0]">select product</td> </tr> ~; $id = ++$id; } print qq~<tr><td><input type=submit name=submit value="purchase item"></td></tr></form></table></body></html>~; $dbh->disconnect(); } sub checkout { @values = ('yes', 'no'); print "<h3>product purchasing</h3><table border=2 align=left>"; foreach (@productid) { $select = qq~select * catalog id='$_'~; $dbh=dbi->connect($connectioninfo,$user,$passwd); $sth=$dbh->prepare($select); $sth->execute(); while (@row=$sth->fetchrow_array()) { print qq~ <tr><td>$row[1]<br>$row[2]<br>\$$row[3]<br><img src=/images/$row[4] height=100 width=100 alt="product image not found."><br></td></tr>~; $total = $total + $row[3]; } } print "<h4>your total \$$total</h4>"; print "</table>"; print "<table border=2 align=center>"; print start_form( -name => "complete" ), '<tr><td>credit card:', radio_group( -name => 'radio1', -values => ['visa', 'mastercard', 'american express'], -columns => 3, -rows => 1, ), '</td></tr>', '<tr><td>credit card number:</td><td>', textfield('cardnum'), '</td></tr>', '<tr><td>', submit(-name => 'submit', -value => 'checkout'), '</tr></td></table>', end_form; foreach (@productid) { print start_form(-name=>"complete"), hidden( -name => "productid", -value => "$_", -override => 1 ), print end_form; } } sub completecheckout { $uid = $cookievalue; $cardtype = param('radio1'); $cardnum = param('cardnum'); foreach $product (@productid) { $insert = qq~insert transaction (uid, pid, cctype, ccnum) values ('$uid', '$product', '$cardtype', '$cardnum')~; $dbh=dbi->connect($connectioninfo,$user,$passwd); $sth=$dbh->prepare($insert); $sth->execute(); } print header; print qq~<html><head><title>yay</title></head><body><p>check mysql<p><p>@productid $uid $cardtype $cardnum</p></body></html>~; }
i have made script displays products sql table , allows user select multiple products, each product uploaded transaction table separate transaction unique id. however, @productid array not being passed completecheckout function, , no information uploaded table.
i realize script bit messy, working on right now, please don't comment on redundant code aware of it.
i cannot identify why form unable read hidden fields.
print "<h4>your total \$$total</h4>"; print "</table>"; print "<table border=2 align=center>"; print qq~<form method=post action=""> <tr><td><input type="radio" name="radio1" value="visa" checked="checked">visa</td> <td><input type="radio" name="radio1" value="mastercard">mastercard</td> <td><input type="radio" name="radio1" value="amex">amex</td></tr> <tr><td>credit card number:</td><td><input type=text name=cardnum></td></tr> <tr><td><input type=submit name=submit value=checkout></tr></td></table>~; foreach (@productid) { print qq~<input type=hidden name=productid value=$_>~; } print qq~</form>~; }
changing cgi pure html worked. passing hidden value's.
Comments
Post a Comment