It's for a simple register/login script I'm working on. All the information (username, email, and password) is going into the database fine. The password is going in md5($_POST['userpass']); so it's encrypted. Here's the problem I have:
login.html:
********
<form action="login.php" method="post">
Username: <input type="text" name="username" size="10">
Password: <input type="password" name="userpass" size="10">
<input type="submit" value="submit" name="submit">
</form>
********
login.php:
********
<?
//replace username and password with your mysql name and password
$conn = mysql_connect("localhost","***","***");
//select the database
$db = mysql_select_db("***");
$username = $_POST['username'];
$email = $_POST['email'];
$userpass = md5($_POST['userpass']);
$sql = "select * from users where username='$username' and password='$userpass'";
$result = mysql_query($sql);
if (mysql_num_rows($result)!= 1) {
$error = "Login failed";
echo "Login failed";
} else {
$_SESSION['username'] = "$username";
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
// any other data needed to navigate the site or
// to authenticate the user can be added here
echo "Welcome";
}?>
********
When I run the script (yes the information is in the database), it says Login failed, which means mysql_num_rows($result)!= 1), however...it does. I've taken out the password part in the $sql line and it seems to work fine, so something with the md5 encryption isn't working. Is there a better/another way to do this, or is there something really wrong here?
Thanks!