anne3marie Posted May 31, 2012 Share Posted May 31, 2012 I have a html form drop down list of produce which my customers chose from. The options in the form are automatically populated from a database. When submitted, the form updates the list of produce in mysql database. I want to add an if statement which allows the customer to not change that selection (leave it as it currently is in the database). There is currently a 'do not update' selection option if($item_1=='do not replace'){}. I don't know how to finish this statement or if something like this will work. Or is there a way to set up my html form that the menu select form automatically submits no item_1 if nothing is chosen? Thanks! This is the code for my selection menu <select id="item1" name="item1"> <?php require('db.php'); $cdquery="SELECT items FROM food"; $cdresult=mysql_query($cdquery) or die ("Query to get data from table failed: ".mysql_error()); while ($cdrow=mysql_fetch_array($cdresult)) { $cdTitle=$cdrow['items']; echo "<option> $cdTitle </option>"; } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/263411-update-php-with-if-statements/ Share on other sites More sharing options...
requinix Posted May 31, 2012 Share Posted May 31, 2012 You're saying this "do not replace" code is already written and ready to be used? Then add a Whatever you want it to say into the SELECT - probably as the first option. Quote Link to comment https://forums.phpfreaks.com/topic/263411-update-php-with-if-statements/#findComment-1350002 Share on other sites More sharing options...
anne3marie Posted May 31, 2012 Author Share Posted May 31, 2012 No 'do not replace' is simply one of the options that is populated from the database. The other options are carrots, tomatoes, celery, etc. I thought that I could use an if statement to tell it not to update when that option was chosen, but it seems this is not the way to do it. I need to make a selection option that does not update the database but I do not know how to do it. My update code is below. I am currently only working with item 1 until I get this figured out <?php include 'db.php'; session_start(); $item_1 = $_POST['item1']; $item_2 = $_POST['item2']; $item_3 = $_POST['item3']; $item_4 = $_POST['item4']; $item_5 = $_POST['item5']; $item_6 = $_POST['item6']; $item_7 = $_POST['item7']; $item_8 = $_POST['item8']; $item_9 = $_POST['item9']; $item_10 = $_POST['item10']; $userid=$_SESSION[userid]; $query = "UPDATE users SET item_1 = '$item_1' WHERE userid='$userid'"; if(mysql_query($query)){ echo "updated";} else{ echo "fail";} ?> Quote Link to comment https://forums.phpfreaks.com/topic/263411-update-php-with-if-statements/#findComment-1350005 Share on other sites More sharing options...
requinix Posted May 31, 2012 Share Posted May 31, 2012 if (item is not "do not replace") { update database with new item } Quote Link to comment https://forums.phpfreaks.com/topic/263411-update-php-with-if-statements/#findComment-1350010 Share on other sites More sharing options...
anne3marie Posted May 31, 2012 Author Share Posted May 31, 2012 I changed the option to "none" and wrote this. It seems to work. Thanks for the help! if($item_5=='none'){ ;} else{$query5 = "UPDATE users SET item_5 = '$item_5' WHERE userid='$userid'";} Quote Link to comment https://forums.phpfreaks.com/topic/263411-update-php-with-if-statements/#findComment-1350087 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.