evanct Posted June 8, 2009 Share Posted June 8, 2009 So I have this simple query: $sql="UPDATE users SET link_bg_size=$dimension WHERE user_id=$id"; mysql_query($sql) or die('Could not insert link_bg_size: '.mysql_error()); The strange part is although it isn't working(and should work), I don't get any mysql errors or even relevant php notices. I echoed $sql and it's all correct: UPDATE users SET link_bg_size=200 WHERE user_id=3 Yet when I refresh phpmyadmin the old link_bg_size value is still there. What might be going on here? Quote Link to comment Share on other sites More sharing options...
gevans Posted June 8, 2009 Share Posted June 8, 2009 Do you have error reporting on? Are you connected to the correct db? Have you checked the result of mysql_query? Quote Link to comment Share on other sites More sharing options...
evanct Posted June 8, 2009 Author Share Posted June 8, 2009 -Like I said, there were no relevant php notices. -Yes. -Isn't that the purpose of 'or die()'? Quote Link to comment Share on other sites More sharing options...
gevans Posted June 8, 2009 Share Posted June 8, 2009 -Like I said, there were no relevant php notices. I asked if you had error reporting on, if you don't php errors will not be displayed (even if their fatal you'll just see a blank screen). -Isn't that the purpose of 'or die()'? No the purpose of or die() is different, and shouldn't be used... see this article - http://www.phpfreaks.com/blog/or-die-must-die Just because the query is successful doesn't mean anything happened. $result = mysql_query(your query); if($result) { echo 'affected rows'. mysql_affected_rows($result); } else { echo 'there was a problem'; } Quote Link to comment Share on other sites More sharing options...
evanct Posted June 8, 2009 Author Share Posted June 8, 2009 When I say 'there were no relevant php notices' that implies that I had notices turned on but no relevant ones were displayed. But anyway, I tried that and all I got was a warning telling me that the argument for mysql_affected_rows is not a valid mysql-link resource. Quote Link to comment Share on other sites More sharing options...
gevans Posted June 8, 2009 Share Posted June 8, 2009 Sorry, my mistake; mysql_affected_rows($result) should be mysql_affected_rows() When I say 'there were no relevant php notices' that implies that I had notices turned on but no relevant ones were displayed. Don't worry I was only checking. I'd look pretty stupid if we went through this and it could've been solved a lot easier, if I hadn't assumed that you had implied the above... Quote Link to comment Share on other sites More sharing options...
evanct Posted June 8, 2009 Author Share Posted June 8, 2009 Okay, now mysql_affected_rows() just returns 0. not much of an improvement. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 8, 2009 Share Posted June 8, 2009 In phpMyAdmin or via command line, please run - DESC users; and post your result here. Also run SELECT COUNT(*) FROM users WHERE user_id=3 LIMIT 1; and post the result here. Quote Link to comment Share on other sites More sharing options...
gevans Posted June 8, 2009 Share Posted June 8, 2009 Well, nothing's failing, it just isn't updating anything. echo ut the query after you show the effected rows. If it's the same as following; UPDATE users SET link_bg_size=200 WHERE user_id=3 Make sure user_id of 3 exists in the table Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 8, 2009 Share Posted June 8, 2009 If $id contains some non-printing leading characters, the 3 won't be seen and the WHERE clause won't match any rows. Do - var_dump($id); And are you sure there is a row with user_id=3? Quote Link to comment Share on other sites More sharing options...
evanct Posted June 8, 2009 Author Share Posted June 8, 2009 good call, var_dump($id) revealed that it was the string '3' rather than the integer 3. so i changed it to an integer and everything worked. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 8, 2009 Share Posted June 8, 2009 If $id was a string that only contained the character 3 or even if it contained '3' (including the quotes as part of the string), it would have worked. About the only way it would not work is if something else was part of the string too, such as sql escape characters or some other non-numeric leading character(s). Quote Link to comment Share on other sites More sharing options...
evanct Posted June 8, 2009 Author Share Posted June 8, 2009 hmm. Well, i refreshed phpmyadmin and the correct value was in link_bg_size. the string was just '3', so i don't know. Quote Link to comment 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.