我将此代码编写为简单的登录脚本。但我不确定语法。我的PHP编辑器告诉我,我尝试重定向到主菜单时出错。我查找了Header()函数,它似乎在Internet上以相同的方式输入。有什么帮助吗?
<?php
ob_start();
$host="localhost"; // Host name
$username="xexink"; // Mysql username
$password="login1"; // Mysql password
$db_name="users_admin"; // Database name
$tbl_name="users"; // Table name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$loginusername=$_POST['myusername'];
$loginpassword=$_POST['mypassword'];
$loginusername = stripslashes($username);
$loginpassword = stripslashes($password);
$loginusername = mysql_real_escape_string($username);
$loginpassword = mysql_real_escape_string($password);
$sql="SELECT * FROM $tbl_name WHERE username='$loginusername';
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
header("location:Main_Menu_User.html");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
答案 0 :(得分:0)
Sql查询应该是这样的
$sql="SELECT * FROM $tbl_name WHERE username='".$loginusername."'";
Do not use `mysql_` functions they are deprecated. Use `PDO` or `mysqli`