Guest Posted August 18, 2012 Share Posted August 18, 2012 In the below URL if a person chooses "what" or "whatever2" how would I get the price to adjust upwards or downwards based on what they choose? Would that be related to a mysql statement? Thanks man! For example, if they choose "whatever" the price goes up for 100 or "whatever2" the price goes down by 100. How would I do something like that? Thanks! http://whatsmyowncarworth.com/auto-members/math/math.php Link to comment https://forums.phpfreaks.com/topic/267269-how-to-change-a-number-based-on-what-someone-chooses/ Share on other sites More sharing options...
Christian F. Posted August 18, 2012 Share Posted August 18, 2012 $priceMods = array ('whatever' => 100, 'whatever2' => -100); if (isset ($priceMods[$_POST['options']]) { $price += $priceMods[$_POST['options']]; } And if you're smart, then you'll use the same $priceMods array to build the dropdown selection. Link to comment https://forums.phpfreaks.com/topic/267269-how-to-change-a-number-based-on-what-someone-chooses/#findComment-1370463 Share on other sites More sharing options...
Guest Posted August 19, 2012 Share Posted August 19, 2012 Hey Christian, Thanks for the code, I appreciate it but I keep on getting an error. It's a simple error but I can't seem to figure it out or where I should delete or move the {. Below is my syntax. What am I doing wrong? Thanks everyone! <?php //Connect to the database through our include include "connect_to_mysql.php"; // Query member data from the database and ready it for display $sql = mysql_query("SELECT price FROM car_data2"); while($row = mysql_fetch_array($sql)){ $price = $row["price"]; } ?> <?php $priceMods = array ('whatever' => 100, 'whatever2' => -100); if (isset ($priceMods[$_POST['choose']]) { $price += $priceMods[$_POST['choose']]; } ?> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> <?php echo "$price"; ?> <form action="math.php" method="post" enctype="multipart/form-data" name="form" id="form" onSubmit="return validate_form ( );"> <table> <tr> <td>Choose:</td> <td> <select name="choose"> <option value="whatever">Whatever</option> <option value="whatever2">Whatever2</option> </select> </td> </tr> <tr> <td width="99"> <input type="submit" name="submit" value="Contact Us"> </td> </tr> </table> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/267269-how-to-change-a-number-based-on-what-someone-chooses/#findComment-1370658 Share on other sites More sharing options...
Christian F. Posted August 19, 2012 Share Posted August 19, 2012 What is the error message you're getting? Link to comment https://forums.phpfreaks.com/topic/267269-how-to-change-a-number-based-on-what-someone-chooses/#findComment-1370668 Share on other sites More sharing options...
Guest Posted August 19, 2012 Share Posted August 19, 2012 Hey, I'm getting a parsing error. Parse error: syntax error, unexpected '{' in /home/scm22ri/public_html/whatsmyowncarworth.com/auto-members/math/math.php on line 25 I've tried a million times to rewrite the code but I don't know what I'm doing wrong. Error is turned on (you can't see that in my above syntax). Thanks! Link to comment https://forums.phpfreaks.com/topic/267269-how-to-change-a-number-based-on-what-someone-chooses/#findComment-1370720 Share on other sites More sharing options...
ialsoagree Posted August 22, 2012 Share Posted August 22, 2012 Hey, I'm getting a parsing error. Parse error: syntax error, unexpected '{' in /home/scm22ri/public_html/whatsmyowncarworth.com/auto-members/math/math.php on line 25 I've tried a million times to rewrite the code but I don't know what I'm doing wrong. Error is turned on (you can't see that in my above syntax). Thanks! If you haven't already figured it out, you need to close 1 of your parathensis: if (isset ($priceMods[$_POST['choose']]) { Should be: if (isset ($priceMods[$_POST['choose']])) { Link to comment https://forums.phpfreaks.com/topic/267269-how-to-change-a-number-based-on-what-someone-chooses/#findComment-1371497 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.