I created a very generic registration script (user name and password, password is md5 hashed). Now I'm trying to create the login script, however, no matter what user name and password you use, tells you invalid user name and/or password. Here's the code:
<html>
<title>WebCp Alpha 1</title>
<body>
<form method="post" action="<?PHP_SELF?>">
User Name: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" name="submit" value="Submit">
<?php
$db = mysql_connect("localhost", "USERNAME", "PASSWORD");
if (!$db) {
echo("Could not establish a connection to the database server.");
exit();
}
mysql_select_db("DBNAME");
if(! @mysql_select_db("DBPASSWORD")) {
echo("Could not establish a connection to the database.");
exit();
}
$sql = "SELECT * FROM user WHERE username = '$username' AND password = '$password'";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
if($submit == "Submit") {
if ($num != "0") {
echo("Logged in!");
exit();
} else {
echo("Invalid user name and/or password. Please try again.");
exit();
}
}
?>
The registration script I created works fine, I've tested it out (except logging in, which is what I'm trying to do here).
Any help is greatly appreciated. Thanks! 🙂