Jax2 Posted April 23, 2010 Share Posted April 23, 2010 Hi all... I'm kind of perplexed here. I've been writing simple sql queries for quite a long time now and I've never run into one not working that I couldn't find an error in, usually a typo, until now. Here is the code: $new_enc=md5($new1); // password - new, encrypted to MD5. $sql2="UPDATE host_locations SET passwd=".$new_enc." where location_id=".$_SESSION['SESS_LOCATION_ID'].""; echo $sql2; $result2=mysql_query($sql, $db) or die(mysql_error()); When I echo the statement, it returns the following: UPDATE host_locations SET passwd=a8687181f3a5a793608acd2215d83a49 where location_id=3 which is exactly right. Yet, for some odd reason, the database isn't storing the new password. I've triple checked my variables, they're correct, and I'm getting the location_id so I know I am connecting correct. mysql_error is returning no errors either. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/199538-update-not-working-cant-find-any-errors/ Share on other sites More sharing options...
Jax2 Posted April 23, 2010 Author Share Posted April 23, 2010 Also, I have turned on strict error reporting, which is also not returning any errors :/ Seems like everything is fine, except for the DB not being updated. Link to comment https://forums.phpfreaks.com/topic/199538-update-not-working-cant-find-any-errors/#findComment-1047313 Share on other sites More sharing options...
Pikachu2000 Posted April 23, 2010 Share Posted April 23, 2010 Try enclosing the $new_enc variable in single quotes in the query string, as it's a string, not an integer. . . . passwd='" . $new_enc . "' WHERE . . . Link to comment https://forums.phpfreaks.com/topic/199538-update-not-working-cant-find-any-errors/#findComment-1047315 Share on other sites More sharing options...
Jax2 Posted April 23, 2010 Author Share Posted April 23, 2010 Thanks for the quick reply ... unfortunately, I just tried that and had no more success than the previous attempt. The old password hash is still there :/ Link to comment https://forums.phpfreaks.com/topic/199538-update-not-working-cant-find-any-errors/#findComment-1047317 Share on other sites More sharing options...
Pikachu2000 Posted April 23, 2010 Share Posted April 23, 2010 What happens if you echo the query, then paste it in to phpMyAdmin, or the mySQL command line client? Does it execute successfully and update the value? Link to comment https://forums.phpfreaks.com/topic/199538-update-not-working-cant-find-any-errors/#findComment-1047318 Share on other sites More sharing options...
Jax2 Posted April 23, 2010 Author Share Posted April 23, 2010 What happens if you echo the query, then paste it in to phpMyAdmin, or the mySQL command line client? Does it execute successfully and update the value? Let me try that quickly. One moment. (Good suggestion!) Link to comment https://forums.phpfreaks.com/topic/199538-update-not-working-cant-find-any-errors/#findComment-1047319 Share on other sites More sharing options...
Jax2 Posted April 23, 2010 Author Share Posted April 23, 2010 Yes, the update command works perfectly ... it updated the right record as it should have. Which makes this even more confusing to me because I know my sql connection is correct, because if I enter the incorrect current password, it tells me that I used the wrong current, so I know it's connecting. I am using the same query style for both. Link to comment https://forums.phpfreaks.com/topic/199538-update-not-working-cant-find-any-errors/#findComment-1047320 Share on other sites More sharing options...
Pikachu2000 Posted April 23, 2010 Share Posted April 23, 2010 Also, I don't believe you need the trailing concatenation operator and set of double quotes ( ."" ) on the query string. Link to comment https://forums.phpfreaks.com/topic/199538-update-not-working-cant-find-any-errors/#findComment-1047323 Share on other sites More sharing options...
Jax2 Posted April 23, 2010 Author Share Posted April 23, 2010 *slaps forehead* After searching 20 minutes, and going through all this, found the problem ... I am calling result2=mysql_query($sql, $db); when it should have been ($sql2, $db) God I can't tell you how much I hate stupid mistakes like that. Link to comment https://forums.phpfreaks.com/topic/199538-update-not-working-cant-find-any-errors/#findComment-1047324 Share on other sites More sharing options...
Pikachu2000 Posted April 23, 2010 Share Posted April 23, 2010 Yeah, I can see as where that could be an issue . . . Link to comment https://forums.phpfreaks.com/topic/199538-update-not-working-cant-find-any-errors/#findComment-1047325 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.