Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Revised Basic script help

by zealf (Novice)
on Feb 20, 2010 at 14:13 UTC ( #824379=note: print w/replies, xml ) Need Help??


in reply to Re^3: Basic script help
in thread Basic script help

Hi there, I am finally making sense of what is going on. The tutorials I am working on have left out some vital informaiton, for example which file names to use and how each file works together. So far I have found a main html file executes a cgi file then executes another cgi file. When submitted of course. So here things go My main systems.html
<html> <head> <title>My first computer Prog </title> </head> <body> <center> <form method="post" action="cgi-bin/fig56.cgi"> <table border=10> <th> <h3> Choose from one of <br>our standard configurations </h3> <tr> <td> Pentium 100 <input type="radio" name="system" value="P100" > Pentium 75 <input type="radio" name="system" value="P75" checked > Pentium 60 <input type="radio" name="system" value="P60" > 486 DX2 66 <input type="radio" name="system" value="486d66" > <tr> <td> 17 Inch Monitor <input type="radio" name="monitor" value="17inch" > 15 Inch Monitor <input type="radio" name="monitor" value="15inch" che +cked > 14 Inch Monitor <input type="radio" name="monitor" value="14inch" > <tr> <td> Multimedia? <input type="checkbox" name="sound" value="true" checked> Modem? <input type="checkbox" name="modem" value="true" checked> <tr> <td> <input type="submit" value="Get Current Price"> <input type="reset"> <tr> </table> </form> </center> <hr noshade> [ <A HREF="http://www.accn.com"> <img alt="Austin Computer Center " src="home.gif" border=1 A> | <A HREF="pindex.asp"> Parts Index </A> | </body> </html>
Works perfectly, and correctly executes my fig56.cgi file as follows
#!/usr/bin/perl -w push(@Inc,"home/themanin/www/cgi-bin"); require("cgi-lib.pl"); &ReadParse(*input); #Determine the base price based on the system variable if($input{'system'}eq"486d66"){ #set 486 only variables $computer_name = "486DX2-66"; $price = 1099; $memory = 4; $video = "VLB"; } else{ #not a 486 must be a pentium system $computer_name = "Pentium"; $memory=8; $video="pcl"; $cache="256K Cache"; if ($input{'system'}eq"P100"){$price=1799;$ptype=100} elsif($input{'system'}eq"P75"){$price=1550;$ptype=75} elsif($input{'system'}eq"P60"){$price=1450;$ptype=60} } #add extra price for monitors over 14 inch $monitor=$input{'monitor'}; if ($input{'monitor'}eq"17inch"){$price+=650;} elsif($input{'monitor'}eq"15inch"){$price+=200;} #add multimedia system if(defined($input{'sound'})){ $price+=190; $multimedia="Multimedia System"; } #add 14.4 modem price if (defined($input{'modem'})){ $price+=69; $modem="14.4 modem"; } print&PrintHeader; print <<print_tag; <html> <head> <title>$computer_name Systems from Gavyn Mickleson</title> </head> <body> <h1 align=center>Kingsville Computers<br>Melbourne!</h1> <center> <img src="../images/Logo_text.jpg": align="center"> <table border=5> <th colspan=2 align=center> <h2> ${computer_name}$ptype for only \$$price </h2> <tr><td><ul> <li>$memory megs of RAM <li>$cache <li>Enhanced IDE In/Out Controller <li>$monitor NIL SVGA Monitor <li>1 Meg $video SVGA Video Card <li>$multimedia </ul> <td><ul> <li>1.44 Floppy Drive <li>500+ meg Hard Drive <li>Mouse <li>Windows 95 <li>$modem </ul> <tr> <td align=right colspan=2><h2>1 YEAR WARRANTY If your Lucky!</h2> <tr> </table> <h3>Or Build your own</h3> <form method="post" action="List511.cgi"> <table> <th>CPU<th>Memory<th>Hard Disk<th>Video Card<th>Monitor <th>CD ROM <th>Modem <tr> <td> <select name="cpu"> <option value="P100">Pentium 100 <option value="P75">Pentium 75 <option value="P60">Pentium 60 <option value="486d66">486 DX2 66 </select> <td> <select name="memory"> <option value="32 MEG">32 Meg Memory <option value="16 MEG">16 Meg Memory <option value="8 MEG">8 Meg Memory <option value="4 MEG"> 4 Meg Memory </select> <td> <select name="disk"> <option value="1 GIG IDE">1 GIG IDE <option value="850 IDE">850 Meg IDE <option value="560 IDE">560 Meg IDE </select> <td> <select name="video"> <option value="4 MEG">4 Meg card <option value="2 MEG">2 Meg card <option value="1 MEG">1 Meg card </select> <td> <select name="monitor"> <option value="17 INch">17 .28 NI <option value="15 INch"> 15 .28 NI <option value="14 INch"> 14 .28 NI </select> <td> <select name="CD-ROM"> <option value="4X CDROM">Quad Speed <option value="2X CDROM">Double Speed <option value="NONE">NONE </select> <td> <select name="modem"> <option value="28.8 MODEM"> 28.8 <option value="14.4 MODEM">14.4 <option value="NONE">NONE </select> <tr> </table> <input type="submit" value="Get Current Price"> <input type="reset" </form> </center> </body> </html> print_tag
I have found fig.56 to execute with both @INC and @Inc and mapping the directory I have corrected too. My first problem was a -T flag on the path to perl. Aparently used to enable a special user input Taint check. (soon to learn) Now in my fig.56 the html output allows a user to select parts from a drop down menu to build a machine, which in effect executes a List511.cgi file. (as follows) This one currently has me stuck. Any ideas?
#!/usr/bin/perl -w push(@Inc,"home/themanin/www/cgi-bin"); require("cgi-lib.pl"); &ReadParse(*input); open($PRICE_FILE,"sys2.txt"); while(<$PRICE_FILE>){ chop; ($item,$price)=split(/:/,$_,2); $price_list{$item}=$price; } #Determine the base price based on the system variable $price=$price_list{$input{'cpu'}}; if ($input{'cpu'}eq"486d66"){ #set 486 only variables $computer_name="486DX2-66"; $video="VLB"; $price+=$price_list{$input{'memory'}}; $memory=$input{'memory'}; } else{ #not a 486 must be a pentium system $computer_name="Pentium"; $video="pcl"; $cache="256K Cache"; if($input{'memory'}ne"8 MEG"){ $price+=$price_list{$input{'memory'}}; } if ($input{'memory'}eq"4 MEG"){ $memory="8 MEG"; } else{$memory=$input{'memory'};} if($input{'cpu'}eq"P100"){$ptype=100} elseif($input{'cpu'}eq"P75"){$ptype=75} elseif($input{'cpu'}eq"P60"){$ptype=60} } #add extra price for monitors over 14inch $monitor=$input{'monitor'}; $price+=$price_list{$input{'monitor'}}; #add multimedia system if($input{'CD-ROM'}ne"NONE"{ $price+=$price_list{$input{'CD-ROM'}}; if($input{'CD-ROM'}eq"2X CD-ROM"){ $multimedia="Double Speed Multimedia System"; } else{ $multimedia="Quad Speed Mulitmedia System"; } } #add 14.4 modem price if ($input{'modem'}ne"NONE"){ $price+=$price_list{$input{'modem'}}; $modem=$input{'modem'}; } #add disk price $price+=$price_list{$input{'disk'}}; $DISK=$input{'disk'}; #add video $price+=$price_list{$input{'video'}}; $VIDEO=$input{'video'}; print&PrintHeader; #print<$in1>; print<<"print_tag"; <html> <head> <title>$computer_name Systems from your own Gavyn Mickleson</title> </head> <body> <h1 align=center>Kingsville Melbourne<br> Australia</h1> <center> <img src=" " align=left> <table boarder=5> <th colspan=2 align=center><h2> ${computer_name}$ptype for only /$$price </h2> <tr><td><ul> <li>$memory of Ram <li>$cache <li>Enhanced IDE In/Out Controller <li>$monitor NIL SVGA Monitor <li>$VIDEO $video SVGA Video Card <li>$mulitmedia </ul> <td><ul> <li>14.4 Floppy Drive <li>$DISK Hard Drive <li>Mouse <li>Windows 95 <li>$modem </ul> <tr> <td align=right colspan=2><h2>1 year selected warranty<italic>Only if +you worth if</italic></h2> <tr> </table> </center> </body> </html> print_tag
Of course the sys2.txt is in the same directory as follows
P100:1799 P75:1500 P60:1450 486d66:1099 32 MEG:800 16 MEG:300 8 MEG:16 +0 4 MEG:0 1 GIG IDE:175 850 IDE:110 560 IDE:0 4 MEG:320 2 MEG:120 1 M +EG:0 17 INch:650 15 INch:200 14 INch:0 4X CDROM:290 2X CDROM:190 NONE +:0 28.8 MODEM:139 14.4 MODEM:69 NONE:0
BTW I did hand all type these. Gavyn

Replies are listed 'Best First'.
Re^5: Basic script help
by Corion (Pope) on Feb 20, 2010 at 14:19 UTC

    No. Your files live in a directory on the server. Maybe the directory is /home/zealf/cgi-files. This directory is then mapped to the URL http://themaninthecharcoalsuit.com.au/cgi-bin. Perl wants to talk about the directory, not the URL. It might be that the directory is /home/zealf/cgi-bin, or even /home/web/themaninthecharcoalsuit.com.au/cgi-bin, but that is for you to know, or for you to ask from your hosting provider, or for you to find out, by looking at your shell account and its directory structure.

Re^5: Basic script help
by YuckFoo (Abbot) on Feb 20, 2010 at 20:50 UTC
    Find your error log! Mine said this:

    malformed header from script. Bad header=Hello World Gavyn J Mickleson

    Indeed the first script wrote a header, the second did not.

    I second the recommendation of the CGI module and tutorials.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://824379]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2020-01-21 02:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?