// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$number=$_POST['number'];
$password=$_POST['password'];
// To protect MySQL injection (more detail about MySQL injection)
$number = stripslashes($number);
$password = stripslashes($password);
$number = mysql_real_escape_string($number);
$password = mysql_real_escape_string($password);
$password = hash('sha512', $password);
$sql="SELECT * FROM $tbl_name WHERE number='$number' and password='$password'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
session_start();
$row=mysql_fetch_array($result);
// Register $myusername, $mypassword and redirect to file "login_success.php";
$_SESSION['firstname'] =$row['firstname'];
$_SESSION['secondname'] =$row['secondname'];
$_SESSION['email'] =$row['email'];
$_SESSION['vote'] =$row['vote'];
$sow = $row['number'];
header("location:User/User.php?id=$sow");
}
else {
echo $error = "Wrong Username or Password";
}
ob_end_flush();
?>
Whenever i click on the login button from my form it automatically says "wrong username or password"? The information is extracted from my database and im trying to extract number and password for login! This is my PHP code to check the login