Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Server Side Programming
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 07-21-2000, 07:03 PM
  #1
prg25
Novice (Level 1)
 
Join Date: Jul 2000
Posts: 6
iTrader: (0)
prg25 is on a distinguished road
Post

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?

prg25 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-21-2000, 09:30 PM
  #2
Jacob
Lord (Level 16)
 
Join Date: Oct 2000
Location: Michigan
Posts: 542
iTrader: (0)
Jacob is on a distinguished road
Lightbulb

First lemme get your code into the code format.

<BLOCKQUOTE><font size="1" face="Verdana, Arial">code:</font><HR><pre>
#!/usr/bin/perl
print "Content-type:text/html\n\n";
open(INF,"mailorder.db") or dienice("Can't open mailorder.db: $! \n");
@grok = &lt;INF&gt;;
close(INF);
print &lt;&lt;EndHdr;
&lt;html&gt;&lt;head&gt;&lt;title&gt;Chesterfield Kings Mail Order&lt;/title&gt;&lt;/head&gt;
&lt;body bgcolor="CC99CC" leftmargin="25" topmargin="4"&gt;
&lt;table width="595" border="0" cellspacing="0" cellpadding="0" align="center"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;h4 align="center"&gt;&lt;b&gt;Chesterfield Kings Online Mail Order&lt;/b&gt;&lt;/h4&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p align="center"&gt;&lt;b&gt;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.&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;form action="order.cgi" method="POST"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
EndHdr

foreach $i (@grok) {
chomp($i);
($stocknum,$imagefile,$title,$description,$price) = split(/\|/,$i);
if ($price ne "0") {
print "&lt;input type=\"text\" name=\"$stocknum\" size=5&gt;

$imagefile - \$title - \$description - \$$price&lt;p&gt;&lt;b&gt;\n";
}
}

print &lt;&lt;EndFoot;
&lt;input type="submit" value="Order!"&gt;&lt;p&gt;
&lt;/body&gt;&lt;/html&gt;
EndFoot

sub dienice {
my($msg) = @_;
print "&lt;h4&gt;Error&lt;/h4&gt;\n";
print $msg;
exit;
}

[/code]

It will make it easier for looking at.


------------------
Jacob A. Wheeler
Co-Founder / Web Engineer
Big Resources Network
jacob@bigresources.com
ICQ: 390147
Jacob is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-21-2000, 09:40 PM
  #3
Jacob
Lord (Level 16)
 
Join Date: Oct 2000
Location: Michigan
Posts: 542
iTrader: (0)
Jacob is on a distinguished road
Lightbulb

Ok, Lemme correct a few problems in your code, that I can see off hand.

<BLOCKQUOTE><font size="1" face="Verdana, Arial">code:</font><HR><pre>
code....
EndHdr

foreach $i (@grok) {
chomp($i);
($stocknum,$imagefile,$title,$description,$price) = split(/\|/,$i);
if ($price ne "0") {
print "&lt;p&gt;&lt;input type=\"text\" name=\"$stocknum\" size=\"5\"&gt;

&lt;img src=\"$imagefile\"&gt; - $title - $description - $price&lt;/p&gt;&lt;b&gt;\n";
}
}

print &lt;&lt;EndFoot;
&lt;input type="submit" value="Order!"&gt;&lt;p&gt;
&lt;/body&gt;&lt;/html&gt;
EndFoot
}

[/code]

I fixed up some of the code around where you were ouputing the results of the database. I also added some image code, to display the value of $image (assuming $image = url to a graphic file)

Tell me if you understand so far.

Regards,

------------------
Jacob A. Wheeler
Co-Founder / Web Engineer
Big Resources Network
jacob@bigresources.com
ICQ: 390147
Jacob is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-21-2000, 09:48 PM
  #4
prg25
Novice (Level 1)
 
Join Date: Jul 2000
Posts: 6
iTrader: (0)
prg25 is on a distinguished road
Post

Ok so far....
prg25 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-24-2000, 01:56 PM
  #5
Jacob
Lord (Level 16)
 
Join Date: Oct 2000
Location: Michigan
Posts: 542
iTrader: (0)
Jacob is on a distinguished road
Lightbulb

Dear Sir,

Could you please post a sample line of your database the script is reading from?

Thanks,


------------------
Jacob A. Wheeler
Co-Founder / Web Engineer
Big Resources Network
jacob@bigresources.com
ICQ: 390147
Jacob is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-24-2000, 03:40 PM
  #6
prg25
Novice (Level 1)
 
Join Date: Jul 2000
Posts: 6
iTrader: (0)
prg25 is on a distinguished road
Post

Here's a line of the database. i changed the name to mailorder2.db, I made some changes to mailorder.db I am going to try it the way i am asking you for help with but I also want to try and do it another way and see which works out. Thanks for all the help.

MR-1|imgoing.jpg|"I'm Going Home" b/w "A Dark Corner"|7 inch|3.50
prg25 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-25-2000, 10:11 PM
  #7
Jacob
Lord (Level 16)
 
Join Date: Oct 2000
Location: Michigan
Posts: 542
iTrader: (0)
Jacob is on a distinguished road
Question

Ok,

I'm looking at this page right now:
http://www.hawkmountaininn.com/cking...rder_frame.htm

Is this the order form your working on?

If so, have you had any luck getting the image to load? I see that it's printing the name of the image next to the broken image.

Did you try adding the image code like I said in two posts ago?

Regards,


------------------
Jacob A. Wheeler
Co-Founder / Web Engineer
Big Resources Network
jacob@bigresources.com
ICQ: 390147
Jacob is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-25-2000, 10:20 PM
  #8
prg25
Novice (Level 1)
 
Join Date: Jul 2000
Posts: 6
iTrader: (0)
prg25 is on a distinguished road
Post

Yes I put the code in as it was show in your reply... I noticed that it was doing that as well.
prg25 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart



 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  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 On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 03:43 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.