[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] R: [PHP] Shopping with variables
?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? Try with replacing your print with the following one: print( You have asked to purchase DVD: $dvd VIDEO: $video CD: $cd 's - ... it should work. Bye Gabriele -- 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]
Re: [PHP] Shopping with variables
Hello Tarrant, Wednesday, May 16, 2001, 12:12:43 PM, you wrote: TC ?php print( You have asked to purchase $dvd $video $cd 's - Thank you) ? TC This prints out, You have bought 16 - Thank you for example, see the TC problem? How do I get it to print the variable name not just it's value? Use ?php print( You have asked to purchase . ($dvd ? DVD: $dvd :''). ($video ? Video: $video :''). ($cd ? CD's: $cd :''). - Thank you) ? -- Best regards, Vitalimailto:[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]
[PHP] R: [PHP] Shopping with variables
Thanks Gabriele :) Whilst waiting for your e-mail I figured out another way...Thought I would show you it just in case you ever find the need to use this alternative: ?php print( You have asked to purchase . ($dvd ? DVD: $dvd :''). ($video ? Video: $video :''). ($cd ? CD's: $cd :''). - Thank you) ? Best Regards Taz This should work even better. Ciao Gabriele -- 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]
RE: [PHP] Shopping with variables
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=DVDDVD/OPTION OPTION VALUE=VIDEOVIDEO/OPTION OPTION VALUE=CDCD/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]
RE: [PHP] Shopping with variables
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=DVDDVD/OPTION OPTION VALUE=VIDEOVIDEO/OPTION OPTION VALUE=CDCD/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] -- 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]
RE: [PHP] Shopping with variables
why not use serialized arrays stored in cookies to store a growing list of things that the user is purchasing? then, it'd be as easy as having this array stored as a single cookie... ;) $items = array( #indexed by item ID '1003045' = array( 'name' ='The best movie', 'type'='DVD', 'quan'=1, ), ); then you could loop thru the array and have all the information right at your fingertips print You ordered $items[$current]['quan'] of $items[$current]['type']; -Original Message- From: John Monfort [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 16, 2001 9:02 AM To: Ralph Guzman Cc: Tarrant Costelloe; [EMAIL PROTECTED] Subject: RE: [PHP] Shopping with variables 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=DVDDVD/OPTION OPTION VALUE=VIDEOVIDEO/OPTION OPTION VALUE=CDCD/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] -- 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]