Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Price updating script ideas

by FoncÚ (Scribe)
on Sep 25, 2002 at 14:14 UTC ( #200626=perlquestion: print w/replies, xml ) Need Help??

FoncÚ has asked for the wisdom of the Perl Monks concerning the following question:

I run a small business in which I build very customized computers for home and business users (a lot of gamers, actually), and I want to add some functionality to my website by providing a way for users to have a list of available options, selectable by radio button and divided by category. I then want the price to be updated upon the click of a button.

The problem is, I have almost no idea how to go about doing this. I've moved all of my HTML from the original webpage into acceptable Perl format, but now I've got the issue of creating the CGI to do this. I thought something like the following would be good for where the price actually is stated:
if ($opcost = 0) { print "Go to the Options section to calculate!"; } else { print $price; }
Basically, I want the following:
  • A running tally of how much the options will change the original price, i.e., if I get a video card that costs $20 less than the standard, $optioncost -= 20.
  • To factor that total tally into $baseprice, the original price.
  • I'd prefer to have just one file to work with, rather than an HTML file and a CGI file. I've got the HTML Perlized, so that's not so much an issue.
I've worked some with HTML forms and Perl before, but I do not yet understand how to work with things like radio buttons (what values they return, whether to use POST or GET depending on situation), even though I've read that portion of the Llama. I understand that this should be a pretty simple thing to do, but I need help in assembling the parts and understanding.

Thanks in advance for the help!


Replies are listed 'Best First'.
Re: Price updating script ideas
by spartacus9 (Beadle) on Sep 25, 2002 at 14:24 UTC
    The problem is in how you structured your "if ($opcost = 0)" statement. when you declare "if ($opcost = 0)", you are actually setting the value of $opcost to zero, not checking it's value. try "if ($opcost == 0)" instead. the == is for comparison, the single "=" is for setting the variable.
Re: Price updating script ideas
by Zaxo (Archbishop) on Sep 25, 2002 at 15:09 UTC

    use CGI; # or die

    It can take care of both the form writing and the query parsing.

    It also doesn't care whether you use POST or GET. The choice is based on a few secondary properties. GET is always unencrypted and the data shows up in your request log.

    After Compline,

Re: Price updating script ideas
by FoncÚ (Scribe) on Sep 30, 2002 at 12:40 UTC
    Eh...yes, I see about the = and == now. That was just a formatting error in my post.

    Working with CGI is new for me, so, does anyone have a good example of a simple form like this with a detailed explination? I've read the Perldoc CGI entry and am still not quite getting it...

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://200626]
Approved by SparkeyG
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (1)
As of 2023-06-07 21:50 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (29 votes). Check out past polls.