Hey guys, I've been bashing my head around for hours now, over this login script. It's the one I always used, and I know it works on my version of MySQL. It just won't send me through to the correct authorized page, it will always redirect to the "login_failed.php" file.
Any help is much appreciated.
<?php
ob_start();
$host="localhost";
$username="*****";
$password="*****";
$db_name="*****";
$tbl_name="*****";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$myusername=$_POST['user'];
$mypassword=$_POST['pass'];
$encrypted_password=md5($mypassword);
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and passwd='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
session_register("myusername");
session_register("mypassword");
header("location:main.php");
}
else {
header("location:login_failed.php");
}
ob_end_flush();
?>