每次我尝试运行我的脚本时,我都会收到此错误,说 mysql_num_rows(): supplied argument is not a valid MySQL result resource.
我不太确定它为什么这样做。我的目标是让它检查登录的客户是否是管理员。
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
if ($username&&$password)
{
$user = $_SESSION['user'];
//connect
$connect = mysql_connect("localhost","*******_robert","***********") or die ("Couldn't Connect"); //host,username,password
mysql_select_db("virtua15_gateway") or die ("Could not find database");
//query
$get = mysql_query("SELECT * FROM Users WHERE username='$user'");
$numrows = mysql_num_rows($query);
if ($numrows!=0)
{
while ($row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
}
if ($username==$dbusername&&$password==$dbpassword)
{
header( 'Location: index2.php' );
$_SESSION['username']=$dbusername;
}
else
echo "incorrect username and password";
}
else
die ("This user does not exist");
}
else
die("Please enter a username and a password");
while($get = mysql_fetch_assoc($get))
{
$admin = $row['admin'];
}
if ($admin==0)
die ("You are not and admin!");
header('Location: index2.php')
?>