Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/263411-update-php-with-if-statements/
Share on other sites

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";}

?>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.