trouble updating WHERE 2 columns must have a certain value

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
boo_lolly
Forum Contributor
Posts: 154
Joined: Tue Nov 14, 2006 5:04 pm

trouble updating WHERE 2 columns must have a certain value

Post by boo_lolly »

i'm trying to update my table, but the coordinates must fall under TWO specifications. not just one. i'm having trouble figuring out how to do this.
my code:

Code: Select all

<?php
        if(isset($_POST['selected_value'])){
                $sql = "UPDATE item_options_linked
                        SET selected_value_id = ". $_POST['selected_value'] ."
                        WHERE (item_id = ". $_GET['itemID'] ." &&
                               option_id = ". $_POST['option_id'] .")";

                mysql_query($sql) OR die(mysql_error());
        }
?>
my table:

Code: Select all

mysql> SELECT * FROM item_options_linked;
+-----+---------+-----------+-------------------+
| id  | item_id | option_id | selected_value_id |
+-----+---------+-----------+-------------------+
|  13 |       6 |         6 |              NULL |
|  14 |       0 |         5 |              NULL |
|   9 |       4 |         5 |              NULL |
|  11 |       6 |         5 |              NULL |
|  10 |       4 |         6 |              NULL |
|  15 |       0 |         6 |              NULL |
|  17 |       7 |         5 |              NULL |
|  18 |       7 |         6 |              NULL |
|  19 |       4 |         8 |              NULL |
|  20 |       6 |         8 |              NULL |
|  21 |       7 |         8 |              NULL |
+-----+---------+-----------+-------------------+
where's my mistake(s)?
Last edited by boo_lolly on Mon Jan 22, 2007 6:01 pm, edited 1 time in total.
Mohamed
Forum Newbie
Posts: 21
Joined: Fri Jan 19, 2007 6:59 pm
Location: Seattle

Re: tr

Post by Mohamed »

boo_lolly wrote:i'm trying to update my table, but the coordinates must fall under TWO specifications. not just one. i'm having trouble figuring out how to do this.
my code:

Code: Select all

<?php
        if(isset($_POST['selected_value'])){
                $sql = "UPDATE item_options_linked
                        SET selected_value_id = ". $_POST['selected_value'] ."
                        WHERE (item_id = ". $_GET['itemID'] ." &&
                               option_id = ". $_POST['option_id'] .")";

                mysql_query($sql) OR die(mysql_error());
        }
?>
my table:

Code: Select all

mysql> SELECT * FROM item_options_linked;
+-----+---------+-----------+-------------------+
| id  | item_id | option_id | selected_value_id |
+-----+---------+-----------+-------------------+
|  13 |       6 |         6 |              NULL |
|  14 |       0 |         5 |              NULL |
|   9 |       4 |         5 |              NULL |
|  11 |       6 |         5 |              NULL |
|  10 |       4 |         6 |              NULL |
|  15 |       0 |         6 |              NULL |
|  17 |       7 |         5 |              NULL |
|  18 |       7 |         6 |              NULL |
|  19 |       4 |         8 |              NULL |
|  20 |       6 |         8 |              NULL |
|  21 |       7 |         8 |              NULL |
+-----+---------+-----------+-------------------+
where's my mistake(s)?
what about this $_GET['itemID'] , are you sure you don't mean $_POST['itemID']
User avatar
boo_lolly
Forum Contributor
Posts: 154
Joined: Tue Nov 14, 2006 5:04 pm

Re: tr

Post by boo_lolly »

Mohamed wrote: what about this $_GET['itemID'] , are you sure you don't mean $_POST['itemID']
yes, i'm sure. i'm still having trouble figuring out how to update my table where there are two values that must be correct...
User avatar
boo_lolly
Forum Contributor
Posts: 154
Joined: Tue Nov 14, 2006 5:04 pm

Post by boo_lolly »

i figured it out:

Code: Select all

<?php
        if(isset($_POST['selected_value'])){
                $sql = "UPDATE item_options_linked
                        SET selected_value_id = ". $_POST['selected_value'] ."
                        WHERE (item_id = '". $_GET['itemID'] ."' AND
                               option_id = '". $_POST['option_id'] ."')";

                mysql_query($sql) OR die(mysql_error());
        }
?>
Post Reply