-1

我将此代码编写为一个简单的登录脚本。但我不确定语法。我的 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();
?>
4

1 回答 1

0

sql查询应该是这样的

$sql="SELECT * FROM $tbl_name WHERE username='".$loginusername."'";

Do not use `mysql_` functions they are deprecated. Use `PDO` or `mysqli`  
于 2013-09-01T09:12:47.563 回答