当我在表单上输入用户名和密码时,它说错误的用户名和密码,即使这是数据库中的用户名和密码,我也不确定为什么它会跳过if语句并转到其他
<?php
ini_set('display_errors', 1);
ob_start();
$host="localhost"; // Host name
$username="id297187_jk05454"; // Mysql username
$password="********"; // Mysql password
$db_name="id297187_members"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
$con=mysqli_connect("$host", "$username", "$password", "$db_name");
// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$sql="SELECT userid FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysqli_query($con, $sql);
// Mysql_num_row is counting table row
$count=$result['num_rows'];
// If result matched $myusername and $mypassword, table row must be 1 row
if($count>0){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header('Location:login_success.php');
exit;
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
答案 0 :(得分:0)
您尚未定义
session_start();
还会对session_register进行折旧并从php5.4中删除,使用global var
$_SESSION['username'] = $myusername;
还要检查您输入的密码是否为
name="mypassword"
你可能想要清理你的$ _POST变量,因为它们容易被注射。