Jump to content

update php with if statements


anne3marie

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

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.