RE: [PHP] Shopping with variables

From: Date: Wed, 16 May 2001 13:02:04 +0000
Subject: RE: [PHP] Shopping with variables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-53027@lists.php.net to get a copy of this message
That will work, assuming the user is not allowed to purchase multiple items... -John On Wed, 16 May 2001, Ralph Guzman wrote: > 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:tcostelloe@insur-e.net] > Sent: Wednesday, May 16, 2001 2:13 AM > To: 'php-general@lists.php.net' > 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 > tcostelloe@insur-e.net > http://www.insur-e.net > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#53027) next »