Welcome! Log In Create A New Profile Forum Rules

Advanced

Chapter 13 login failure

Posted by Matteo 
Chapter 13 login failure
four years ago
I am using:
phpMyAdmin 2.6.2-pl1
MySQL 4.1.18-log running on localhost

Chapter 13.
I can register successfully.
I click on the link in the email generated by the registration and receive a message that my account is activated and I can log in.
I enter the correct email and password, but I get the error message that either the password/username is not right or else my account is not activated. No match is found by the query, and 0 rows are affected...but when I run the relevant query from phpMyAdmin, it works!

I try logging in using 3 different browsers. All fail.

I am using all scripts that accompany the book verbatim except for making the needed changes for the database connection info and the activating link definition.

Where should I be looking for the solution?
Re: Chapter 13 login failure
four years ago
Have you considered the change in the PASSWORD() function in MySQL with version 4.1? See this post for details: [www.dmcinsights.com]


____________

Paul Swanson
Portland, OR
USA
____________


PHP Version 4.4.0
MySQL Version 4.1.22
Apache Version 1.3.37
Server OS: Linux Version 2.4.20-8
Workstation OS: Windows XP Pro SP2
Re: Chapter 13 login failure
four years ago
Thanks for tip.
I looked at the thread you referred to, and I changed the password field to 41 chars

But the login still does not work.

Re: Chapter 13 login failure
four years ago
After you changed the password field, did you re-register? You need to change the value held in the password column for it to run correctly. Try re-registering so that the new (encoded) password value is stored instead of the old value and try logging in again.

VGMusic
Re: Chapter 13 login failure
four years ago
Yes, I did reregister after changing the password field, but the login still fails.

PHP 5.1.4
Apache 1.3.34 (UNIX)
MySQL 4.1.18
phpMyAdmin 2.6.2-pl1

The example scripts from earlier chapters of the book which used a password worked fine! And as I said, when I run the relevant query from phpMyAdmin, it works. I just can't get it to work from any browser.

Re: Chapter 13 login failure
four years ago
I don't think the PASSWORD() field is the issue as I don't use that function in this book. What is the query the PHP script is trying to run?

Best Wishes,
Larry

Writer/Web Developer/Instructor
Forum Moderator
Re: Chapter 13 login failure
four years ago
The query is from line 34 of script 13.8 login.php:

$query = "SELECT user_id, first_name FROM users WHERE (email='$e' AND pass=SHA('$p')) AND active IS NULL";
Re: Chapter 13 login failure
four years ago
Right, but what is the query that the PHP script is actually trying to run WITH THE VARIABLE VALUES? There's nothing wrong with that query unless...
- the variable values aren't getting in there properly
- you don't have a connection to the database
- your table differs from the one in the book

If you print the value of $query, you can confirm the first possible cause. If you use the mysql_error() function, you can confirm the second and third.

Best Wishes,
Larry

Writer/Web Developer/Instructor
Forum Moderator
Re: Chapter 13 login failure
four years ago
//EXCERPT FROM SCRIPT 13.8
...
if ($e && $p) { // If everything's OK.

// Query the database.
$query = "SELECT user_id, first_name FROM users WHERE (email='$e' AND pass=SHA('$p')) AND active IS NULL";
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());

//THIS IS CODE I ADDED TO TRY TO TEST AS YOU SUGGESTED
$errors[] = mysql_error().'<br /><br />Query: '.$query;
if (!empty($errors))
echo '<h1 id="mainhead">Error!</h1>
<p class="error">The errors are:<br />';
foreach ($errors as $msg){
echo " - $msg<br />\n";
}
echo 'Number of rows affected: '.mysql_num_rows($result);
//END OF TEST CODE

if (@mysql_num_rows($result) == 1) { // A match was made.
...

//THIS IS RESULT
Error!

The errors are:
-

Query: SELECT user_id, first_name FROM users WHERE (email='info@iplusnow.com' AND pass=SHA('sayid')) AND active IS NULL
Number of rows affected:0

QUESTION
Looks to me like the values are inserted correctly and no errors are produced. The trigger_error() function never produced any result. Have I not tested for all 3 of the possiblities you listed?

Re: Chapter 13 login failure
four years ago
Yep, that all looks good. Okay, so you've confirmed that the query is valid and that it is executing in MySQL. There are two possible problems:

- your table differs from the one in the book (you haven't confirmed this). Specifically you might have problems if your active column is defined as NOT NULL.

- You are referring to the number of "affected" rows but a SELECT query NEVER has any "affected" rows. I think this is just a terminology issue, as you are using mysql_num_rows(), not mysql_affected_rows(), correct? However, it would be a good idea to remove the @ from in front of mysql_num_rows() just in case.

Finally, just to confirm, if you run the query "SELECT user_id, first_name FROM users WHERE (email='info@iplusnow.com' AND pass=SHA('sayid')) AND active IS NULL" using phpMyAdmin you do get exactly one row returned, right? And both phpMyAdmin and your PHP scripts are using the same database?

Best Wishes,
Larry

Writer/Web Developer/Instructor
Forum Moderator
Re: Chapter 13 login failure
four years ago
My table was different. I had the pass field set to UNIQUE instead of the email field, and I did not have the pass field indexed. I had overlooked that. Works like a charm now!

I don't know how you have time to answer everybody's questions, but I sure do appreciate the help. Mille Grazie! (A thousand thanks.)

Matteo
Re: Chapter 13 login failure
four years ago
You're very welcome. I did suspect there was a table definition problem and what you described would certainly be the cause.

Best Wishes,
Larry

Writer/Web Developer/Instructor
Forum Moderator
Sorry, only registered users may post in this forum.

Click here to login