I have been trying to learn Perl for writing CGIs. I am working on an online order system based on a flat file database of about 25 products (records of a band actually). I wrote out the database in notepad, and wrote my code in Perl Builder... which isnt much help at all unless your making a form->email. But its nice becuase it color codes things while I'm writing and that helps me alittle. Anyway, I made the database called it mailorder.db, then I write the script...with the help of a book I modifyed it a bit to make it do what I want but I'm not to well versed in this yet to say what array or varaibles I have messed up, or what is wrong..
#!/usr/bin/perl
print "Content-type:text/html\n\n";
open(INF,"mailorder.db") or dienice("Can't open mailorder.db: $! \n");
@grok = <INF>;
close(INF);
print <<EndHdr;
<html><head><title>Chesterfield Kings Mail Order</title></head>
<body bgcolor="CC99CC" leftmargin="25" topmargin="4">
<table width="595" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<h4 align="center"><b>Chesterfield Kings Online Mail Order</b></h4>
</td>
</tr>
<tr>
<td>
<p align="center"><b>To order, enter the quanity of each item you would like in the box next to the item's description. After submitting the form we'll calculate your total.</b></p>
</td>
</tr>
<tr>
<td><form action="order.cgi" method="POST"></td>
</tr>
</table>
EndHdr
foreach $i (@grok) {
chomp($i);
($stocknum,$imagefile,$title,$description,$price) = split(/\|/,$i);
if ($price ne "0") {
print "<input type=\"text\" name=\"$stocknum\" size=5>
$imagefile - \$title - \$description - \$$price<p><b>\n";
}
}
print <<EndFoot;
<input type="submit" value="Order!"><p>
</body></html>
EndFoot
sub dienice {
my($msg) = @_;
print "<h4>Error</h4>\n";
print $msg;
exit;
}
Now, this works but its a bit off, It won't display the image file, I just put the path of the image in the database(<imgsrc="stop.jpg"> ) then it will only display the price. previously I had only entered the path to the image like this.. stop.jpg and when i ran the script I would get the title and the price but nothing else.. it would just print $imagefile - STOP - $description - $title - $12
I want it to show the image then the title of the record then the description then the price.. I would also like to add another form element next to the text box,it would be a select that would allow you to select the format of what you want to buy LP,CD, or CASSETTE (yep these guys are putting out vinyl) but only a few of the items are multi-format so how would i make it recognize that and only put that form element with those items, on this same idea the differnt formats are priced differently... so i would set the value of the LP, CD, CASS to be the price of that format, so when it passes this info to the next form it will enter the correct price for the format chosen by the user. the next form will take the order info add up a total display title, quanity ordered, then ask for some shipping info and contact info. That form is intended to be printed and snail mailed in with payment but I would also like it to e-mail the order to the band so they know its coming, and have a e-mail go out to the person who ordered and say thanks. The url is
http://www.hawkmountaininn.com/ckings hit the mail order button on the navbar. I am in the process of switching domain names on this server and I dont know when they will get it done, so if that URL doesn't work try
www.interplexia.com/ckings and that will get you there. If you want to see the database and the actual script I put it up on my anonftp at ftp.hawkmountaininn.com/pub. Thanks in advance for any guidance, this stuff sure is fun but frustating as well sometimes but thats learning for you. Have fun PG
Would it be easier to make a form with just HTML and have a CGI that would read the data and post it to then next form?