开发者

PHP SQL UPDATE broken?

I am trying to make an update query to update a user to have a password. The update statement is extremely easy and it has been baffling me for about 12 hours now.

I have read everything having to do with this on 3.5 pages of google searches. but for some reason, none of the suggestions work for me!

Here is the UPDATE query in its 'original' form:

$sql_update = "UPDATE users_sensitive SET password = '$password_hash', ch_password = '$password_hash' WHERE email_hash = '$email_hash'";
$result_update = mysql_query($sql_update) or die(mysql_error());

When I do this update Query, I get no errors or anything back. It also just does not update.

Here's another rendition of the same code:

$sql_update = "UPDATE users_sensitive SET password = '" . $password_hash . "', ch_password = '" . $password_hash. "' WHERE email_hash = '" . $email_hash . "'";
$result_update = mysql_query($sql_update) or die(mysql_error());

Again, nothing happens.

When I put the actual numbers in here instead of the php variables:

$sql_update = "UPDATE users_sensitive SET password = '700b5b23b511d974fe9eeb17ad350b33', ch_password = '700b5b23b511d974fe9eeb17ad350b33' WHERE email_hash = 'ac24dab060a172d8c0b3679d8ae61cac'";
$result_update = mysql_query($sql_update) or die(mysql_error());

(don't worry, it's not sensitive info) It does actually update...

So, I'm assuming my syntax is wrong? I know these are Strings instead of just numbers, so I need the single quotes around them. I have the two variables I need echoed and they are both showing exactly what they should be. I have even tried to use backticks around the column name but that didn't do anything?

I did a var_dump and it came back "true".

When I do a print on my $sql_update, I get:

UPDATE users_sensitive SET password = '700b5b23b511d974fe9eeb17ad350b33', ch_password = '700b5b23b511d974fe9eeb17ad350b33' WHERE email_hash = 'ac24dab060a172d8c0b3679d8ae61cac'

There is no whitespace here. When I print the $result_update, it c开发者_运维技巧omes up with: 1

ANSWER Thank you to bemace, James Anderson, VolkerK, alex and the others!

The problem was that there was a strange line break in the code creating whitespace that was not the same as on the database.

After backtracking, I noticed at the very beginning of my code on this page, I used a GET to get a hash number from the URL. While making a variable, during testing, I added a line break to the variable for testing purposes only. I (stupidly) left the line break in there. When using that variable in a hidden form field, it included the line break.

After taking the line break out of the first line, everything matched up and all is good.

If you are reading this and plan on posting later, Posting the entire code is probably worth it. This problem would have been fixed earlier if I had.

Again, Thank you to the quick responses and trouble shooting!


No errors and no updates tells me that your where clause isn't matching anything. Make sure $email_hash doesn't have any leading or trailing whitespace and isn't being truncated.

A less likely possibility is that the update is part of a transaction that is being rolled back.

Another less likely possibility: are you connected to the right server?


Thank you to bemace, James Anderson, VolkerK, alex and the others!

The problem was that there was a strange line break in the code creating whitespace that was not the same as on the database.

After backtracking, I noticed at the very beginning of my code on this page, I used a GET to get a hash number from the URL. While making a variable, during testing, I added a line break to the variable for testing purposes only. I (stupidly) left the line break in there. When using that variable in a hidden form field, it included the line break.

After taking the line break out of the first line, everything matched up and all is good.

If you are reading this and plan on posting later, Posting the entire code is probably worth it. This problem would have been fixed earlier if I had.

Again, Thank you to the quick responses and trouble shooting!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜