好的,所以当我尝试登录时出现此错误:
Notice: Undefined variable: numrows in C:\xampp\htdocs\website\login.php on line 14
该用户不存在。 你是否注意到任何错误,试图学习PHP和MySQL。这是代码
INDEX PHP PAGE
<html>
<form action="login.php" method="POST">
Username: <input type="text" name="username"><br />
Password: <input type="password" name="password"><br />
<input type="submit" name="Login In"><br />
</form>
</html>
PHP登录页
<?php
$username = $_POST['username'];
$password = $_POST['password'];
if ($username&&$password)
{
$connect = mysql_connect("localhost","root","") or die("Couldn't Connect!");
mysql_select_db("phplogin") or die("Couldn't Find DB!");
$query = mysql_query("SELECT * FROM users WHERE username='username'");
$numrow = mysql_num_rows($query);
if ($numrows!=0)
{
// code to login
}
else
die("That user doesn't exist");
}
else
die("Please enter and username and password!");
?>
答案 0 :(得分:3)
if ($numrows!=0)
应为if ($numrow!=0)
你忘记了查询中的$:
$query = mysql_query("SELECT * FROM users WHERE username='".$username."'");