0

I am trying to make a password retrieval system on my site, and I am having problems updating the password reset field in my database. I have tried everything, but nothing seems to work.

This is my code so far:

$passwordreset = md5(mt_rand()) . md5(mt_rand()) . md5(mt_rand());

$con = mysql_connect("localhost","XXX","XXX");
if (!$con) {
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("database", $con);

mysql_query("UPDATE members SET passwordreset = $passwordreset WHERE id = $id");

When I try to insert the data I get the error:

Error: Query was empty

Any help would be appreciated, Thanks.

1
  • Are you sure the message comes from this particular query? How do you get the error? Commented Dec 17, 2009 at 12:51

4 Answers 4

2

Not sure it's the only problem, but I'm guessing your passwordreset field is a string, in the database -- to store a concatenation of several md5, which are strings, it has to.

So, there should be quotes arround the value you put in this field, in the SQL query :

mysql_query("UPDATE members SET passwordreset = '$passwordreset' WHERE id = $id");


And, in a general case, you should escape your string values with mysql_real_escape_string :

mysql_query("UPDATE members SET passwordreset = '" 
    . mysql_real_escape_string($passwordreset) 
    . "' WHERE id = $id");

It won't change anything here, as there is no quote in a md5... But it's a good practice to always do it, to never find yourself in a situation where it was necessary and you didn't do it.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply, still doesn't work, getting the same error
0

I am not sure, if you get an empty query error for this, but you need ticks around the values:

mysql_query("UPDATE members SET passwordreset = '$passwordreset' WHERE id = '$id'");

Comments

0

I guess the backticks around the names of the columns are missing, try:

mysql_query("UPDATE members SET `passwordreset` = '$passwordreset' WHERE `id` = '$id'");

Comments

0

Are the two line breaks after $passwordreset intentional? Can you try removing them?

1 Comment

They shouldn't be a problem. I have lots of long MySQL statements here with line breaks and php / MySQL have no problems with them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.