User Login Registration

step 1: Use PHP bbcode tags around your code. much easier to read for those that try to help.
Step 0: Clear out your passwords before posting your code. (Unless you intentionally put root/root in there, in which case good on you.)

The code appears valid, if somewhat redundant. My first thought though is ‘do you have multiple rows in your database with the same username and different passwords’. The reason being this:

while ($row = mysql_fetch_assoc($query))
$dbusername = $row['username'];
$dbpassword = $row['password'];	

If you pull multiple records with this query, that code will ensure that only the LAST record is used for comparison. (because it will overwrite $dbusername and $dbpassword every time). You may have accidentally MD5’d an MD5 string, which is why the password expects the hash. Take a look in your database and ensure that you only have 1 record for this name, and that it’s password is the hash string you expect.

Apparently so. I’m not sure how to fix the issue, I figured the login.php wasn’t requesting the right password, or it’s not encoding the password before sending it. Any ideas?


The query returns the wrong password? So there was an error when you initially created the account. Try creating a new account and see if the password is entered into the database as the correct hash. (It should be.)

Off Topic:

Yay post 600. Guru status :stuck_out_tongue:

So the query when echoed out looks like…
SELECT * FROM users WHERE username =‘whateveryourusernameis’ AND password=md5(‘12345’)

? Have you run this query directly on the database to ensure it’s working correctly?

Here it is.


	<form action="./login.php" method="post">
    	Username: <input type="text" name="username"><br>
    	Password: <input type="password" name="password"><br>
		<input type="submit" value="login" />
    <a href="register.php">Register</>

I think I see the cause of my frustrations. the “./” always the last place you look, I figured it had something to do with the PHP and not the original piece I coded.

I’ll check it out and see if it works. :lol:
Sorry if I was being frustrating today guys! :smiley: Thanks for putting me in the right direction.

What about the HTML for the actual login form.