AdrianRobinson Posted September 2, 2011 Share Posted September 2, 2011 The following mysql query is not returning rows like I expect it to. '$update_field' is a variable, matching an actual field name in table 'users'. 'user_task[1]' is an integer value. What am I missing here? $query_update_user = "UPDATE users SET ".$update_field." = 'Y' WHERE user_no = '".$user_task[1]."'"; Quote Link to comment https://forums.phpfreaks.com/topic/246265-simple-query-not-working/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 2, 2011 Share Posted September 2, 2011 is not returning rows like I expect it to Yes, but what is it doing, so that we would know what sort of problem you are having and could help find the cause. P.S. UPDATE queries don't return rows, if you literally meant you expected that query to 'return rows' Quote Link to comment https://forums.phpfreaks.com/topic/246265-simple-query-not-working/#findComment-1264682 Share on other sites More sharing options...
AdrianRobinson Posted September 2, 2011 Author Share Posted September 2, 2011 Actually I want to the query to update one row. When I run it, the table doesn't update, as expected...I'm thinking maybe I'm missing or need to add single or double quotes. But the various combinations I've tried did not work. Quote Link to comment https://forums.phpfreaks.com/topic/246265-simple-query-not-working/#findComment-1264683 Share on other sites More sharing options...
PFMaBiSmAd Posted September 2, 2011 Share Posted September 2, 2011 There's nothing technically wrong with the query you posted, provided the variables have expected values, the columns you are referencing exist, the user_no exists, and there are not any other problems in your code such as no database connection... A) echo $query_update_user; so that you know exactly what it contains. B) Are you actually executing the query using a mysql_query() statement? (you would not believe how many times people ask why their query is not doing anything but they don't actually have any code to execute the query.) C) Do you have any error checking and error reporting logic to test if the mysql_query executed without any errors and to tell you if/why the query failed? (if you look at any of the similar threads in the forum, i.e. my query is not working..., you will find suggested code using mysql_error() that test if the query worked or not and displays the mysql_error() output when it does not.) D) Is the code with the query statement and the mysql_query() statement actually being executed? Perhaps it is in a conditional statement that is false or the whole page is not running due to a fatal parse error or a fatal runtime error. Quote Link to comment https://forums.phpfreaks.com/topic/246265-simple-query-not-working/#findComment-1264686 Share on other sites More sharing options...
AdrianRobinson Posted September 2, 2011 Author Share Posted September 2, 2011 Echoing the query helped a great deal. I should have used 'user_task[0]'. D'oh!!! Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/246265-simple-query-not-working/#findComment-1264702 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.