Might want to reconsider the way you are doing this, since this may not be
the most efficient way. An alternative might be to do this as follows:

In your web form set a field for Quantity and another for Item Name, so for
example:

<FORM ACTION="script_name.php" METHOD="post">

...

Quantity: <INPUT TYPE="text" NAME="item_qty" SIZE="2">

<SELECT NAME="item_type">
<OPTION VALUE="DVD">DVD</OPTION>
<OPTION VALUE="VIDEO">VIDEO</OPTION>
<OPTION VALUE="CD">CD</OPTION>
</SELECT>

...

</FORM>

then when you process the form all you would have to do to display your
thank you message:

print "You have asked to purchase $item_qty $item_type. Thank You";

Nevertheless, if for some reason you must do things like you are doing them
now, try something like this:

if(isset($dvd)){
   $item_type = "DVD(s)";
   $item_qty = "$dvd";
}

if(isset($video)){
   $item_type = "VIDEO(s)";
   $item_qty = "$video";
}

if(isset($cd)){
   $item_type = "CD(s)";
   $item_qty = "$cd";
}

print "You have asked to purchase $item_qty $item_name";

Keep in mind that this is not the most efficient method since it will
require that you continue adding if(isset($variable)) statements, if you
ever decide to add more item types.


-----Original Message-----
From: Tarrant Costelloe [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 16, 2001 2:13 AM
To: '[EMAIL PROTECTED]'
Subject: [PHP] Shopping with variables

I am currently just messing around with a basic shopping cart, but have
stumbled onto a problem.
Bascially there is three input boxes all <name> DVD, VIDEO, CD and these are
also variables. Once the user has said they wanted "15" cd's for example,
the form then takes them onto the shop.php. Which say's something along the
lines of:

?php print(" You have asked to purchase $dvd $video $cd 's - Thank you") >?

This prints out, "You have bought 16 - Thank you" for example, see the
problem? How do I get it to print the variable name not just it's value?

Tarrant Costelloe
Software Developer
InsurE-com Ltd.
------------------------------------
Tel:  +44 (0)1273 852014
[EMAIL PROTECTED]
http://www.insur-e.net


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to