Could anyone tell me why the following is not working?
<html>
<body>
<?
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db('database');
if(isset($_POST['username']) && !empty($_POST['username']) AND isset($_POST['password']) && !empty($_POST['password'])){
$username = ($_POST['username']);
$password = ($_POST['password']);
$search = mysql_query("SELECT username, password, active FROM users WHERE username='".$username."' AND password='".$password."'") or die(mysql_error());
$match = mysql_num_rows($search);
}
if($match > 0){
echo 'Login Complete! Thanks';
// Set cookie / Start Session / Start Download etc...
}else{
echo 'Login Failed! Please make sure that you enter the correct details and that you have activated your account.';
}
?>
<h3>Login Form</h3>
<p>Please enter your name and password to login</p>
<!-- start sign up form -->
<form action="" method="post">
<label for="name">Name:</label>
<input type="text" name="name" value="" />
<label for="password">Password:</label>
<input type="password" name="password" value="" />
<input type="submit" class="submit_button" value="Login" />
</form>
</body>
</html>
The connected successfully message comes up, but so does the Login Failed! one. I am not sure what I am doing wrong. The stuff I am typing in exactly matches the database info. (I have changed username, password etc. for this post).
This isn't the finished script but I am just checking as I go along, still need to add cookies, session etc. but it is not looking good if I can't do this!
The script is not originally mine but I am trying to adapt it
Thanks