harkly Posted February 17, 2010 Share Posted February 17, 2010 I am trying to update a field with a random number, it will then send it in an email. I need help with it updating the database. I got the rest working. Not sure how much code is needed but here is where my problem lies-- if($error == 0) { $sql_check = mysql_query("SELECT pswd, userID FROM user WHERE email='".$email."'") or die(mysql_error()); while ($r=mysql_fetch_array($sql_check)) $userID=$r["userID"]; $pswd=mt_rand(10000, 999999); if($forgot == "password") { $sql = "UPDATE user SET pswd='$pswd' WHERE email='$email' or die(mysql_error())"; $result = mysql_query($query) or die(mysql_error()); //These are the variables for the email $to = $email; // this is the email address collected form the form $subject = "email confirmation"; $message = "Your new password $pswd " ; $header = "From: [email protected]\r\n"; $header .= "Reply-to: [email protected]\r\n"; // This is the function to send the email if (mail($to, $subject, $message, $header)) { echo "<p>Message successfully sent!</p>"; } else { echo "<p>Message delivery failed...</p>"; } } WHen I add these lines is when my error happens $sql = "UPDATE user SET pswd='$pswd' WHERE email='$email' or die(mysql_error())"; $result = mysql_query($query) or die(mysql_error()); This gives me the error -- Query was empty Link to comment https://forums.phpfreaks.com/topic/192418-query-was-empty/ Share on other sites More sharing options...
jl5501 Posted February 17, 2010 Share Posted February 17, 2010 you are loading your query into a variable called $sql, then executing a query in a variable $query, which has nothing in it change $query to $sql in your call to mysql_query() Link to comment https://forums.phpfreaks.com/topic/192418-query-was-empty/#findComment-1013875 Share on other sites More sharing options...
harkly Posted February 17, 2010 Author Share Posted February 17, 2010 They should just take the computer away from me! I can't believe I missed that! Thanks Link to comment https://forums.phpfreaks.com/topic/192418-query-was-empty/#findComment-1013890 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.