我的登录表单有问题。我成功连接到数据库。如果我只使用用户名,它会检查数据库,如果用户名存在,它会重定向到另一个页面。如果我使用密码,它不会登录。下面是代码:
<?php
// check _POST data
$myusername=( isset($_POST['myusername']) ) ? $_POST['myusername'] : false;
$mypassword=( isset($_POST['mypassword']) ) ? $_POST['mypassword'] : false;
if( $myusername === false || $mypassword === false ) die('Access forbidden! Go away!');
// hash password
$encrypted_pass=md5($mypassword);
$host="localhost"; // Host name
$username="root"; // username
$password="le30mu09"; // password
$db_name="infobiz_db2"; // Database name
$tbl_name="jos_users"; // Table name
// Replace database connect functions depending on database you are using.
$link=mysql_connect("$host", "$username", "$password");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$db_name");
$sql="SELECT * FROM $tbl_name WHERE Username='$myusername' and Password='$encrypted_pass'";
$result=mysql_query($sql);
mysql_close($link);
if(!$result) {
die('No database' .mysql_error());
}
// Replace counting function based on database you are using.
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
我真的很困惑,无法找到解决方案