boo_lolly Posted January 22, 2007 Share Posted January 22, 2007 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]<?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()); }?>[/code]my table:[code]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 |+-----+---------+-----------+-------------------+[/code]where are my mistake(s)? Link to comment https://forums.phpfreaks.com/topic/35286-trouble-updating-where-2-columns-must-have-a-certain-value/ Share on other sites More sharing options...
hvle Posted January 22, 2007 Share Posted January 22, 2007 if all columns in your item_options_linked user integer, then your query has no error.I would echo the query to make sure it got the $_GET and $_POST right. Link to comment https://forums.phpfreaks.com/topic/35286-trouble-updating-where-2-columns-must-have-a-certain-value/#findComment-166809 Share on other sites More sharing options...
boo_lolly Posted January 22, 2007 Author Share Posted January 22, 2007 [quote author=hvle link=topic=123572.msg510987#msg510987 date=1169509988]if all columns in your item_options_linked user integer, then your query has no error.I would echo the query to make sure it got the $_GET and $_POST right.[/quote]i figured it out:[code]<?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()); }?>[/code] Link to comment https://forums.phpfreaks.com/topic/35286-trouble-updating-where-2-columns-must-have-a-certain-value/#findComment-166810 Share on other sites More sharing options...
hvle Posted January 23, 2007 Share Posted January 23, 2007 actually, if the fields type is number, integer, you do not need to wrap it single quote. Link to comment https://forums.phpfreaks.com/topic/35286-trouble-updating-where-2-columns-must-have-a-certain-value/#findComment-166812 Share on other sites More sharing options...
boo_lolly Posted January 23, 2007 Author Share Posted January 23, 2007 [quote author=hvle link=topic=123572.msg510990#msg510990 date=1169510569]actually, if the fields type is number, integer, you do not need to wrap it single quote.[/quote]true, but item_id and option_id, i believe are VARCHAR, it doesn't hurt. the single quotes and the && -> AND was the source of the problem. Link to comment https://forums.phpfreaks.com/topic/35286-trouble-updating-where-2-columns-must-have-a-certain-value/#findComment-166825 Share on other sites More sharing options...
hvle Posted January 23, 2007 Share Posted January 23, 2007 umm... && is not a problem.It's definitely the varchar type in item_id and option_id. Link to comment https://forums.phpfreaks.com/topic/35286-trouble-updating-where-2-columns-must-have-a-certain-value/#findComment-166827 Share on other sites More sharing options...
fenway Posted January 23, 2007 Share Posted January 23, 2007 That shouldn't matter... it does silent type conversion anyway. Link to comment https://forums.phpfreaks.com/topic/35286-trouble-updating-where-2-columns-must-have-a-certain-value/#findComment-167258 Share on other sites More sharing options...
hvle Posted January 24, 2007 Share Posted January 24, 2007 you're right again,and now, I failed to see any error on the original query. Link to comment https://forums.phpfreaks.com/topic/35286-trouble-updating-where-2-columns-must-have-a-certain-value/#findComment-167775 Share on other sites More sharing options...
fenway Posted January 24, 2007 Share Posted January 24, 2007 Switch it to a SELECT, make sure that you get some matching rows... Link to comment https://forums.phpfreaks.com/topic/35286-trouble-updating-where-2-columns-must-have-a-certain-value/#findComment-167991 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.