Jump to content
Larry Ullman's Book Forums

Mysql 5.1.63 Mandriva Linux - Script 6.11 Gets Value Of Resource Id #5 In Update Query


Recommended Posts

I plugged in a display of $result to see why update is failing (It drops through to "Your username and password do not match our records") and $result contains "Resource id #5".

Is this a compatibility issue? I believe I'm using the first edition of your book, but I've downloaded the scripts posted at your site.

I've done further debugging and it appears I'm failing on the match for password. I've used the register.php script to insert a user, but I can't get a password match when I try to retrieve the record.

Here is the code:

if ($u && $p && $np) { // If everything's OK.

 

$query = "SELECT user_id FROM users WHERE (username='$u' AND password=PASSWORD('$p') )";

$result = @mysql_query ($query);

$num = mysql_num_rows ($result);

if ($num == 1) {

$row = mysql_fetch_array($result, MYSQL_NUM);

 

// Make the query.

$query = "UPDATE users SET password=PASSWORD('$np') WHERE user_id=$row[0]";

$result = @mysql_query ($query); // Run the query.

if (mysql_affected_rows() == 1) { // If it ran OK.

 

// Send an email, if desired.

echo '<p><b>Your password has been changed.</b></p>';

include ('templates/footer.inc'); // Include the HTML footer.

exit(); // Quit the script.

 

} else { // If it did not run OK.

$message = '<p>Your password could not be changed due to a system error. We apologize for any inconvenience.</p><p>' . mysql_error() . '</p>';

}

} else {

$message = '<p>Your username and password do not match our records.</p>' . $result ; //show result for debugging

}

mysql_close(); // Close the database connection.

 

} else {

$message .= '<p>Please try again.</p>';

}

 

} // End of the main Submit conditional.

Link to comment
Share on other sites

Is your password field 41 characters long? The PASSWORD function in earlier versions of MySQL created a 16 character string, but later versions (I forget which version the change was made) create a 41 character string. Your version is definitely creating the longer string, so if your field is defined for less than that the string is getting truncated when it is inserted, and what is in the database won't match your query.

Link to comment
Share on other sites

 Share

×
×
  • Create New...