0

我正在创建一个登录表单,它查询数据库以了解用户是否存在。这个脚本在我自己的服务器上运行良好,但是一旦我在我的大学服务器上尝试过,我就得到了标题中的错误。我认为问题与我的 SQL 查询有关,但我不太确定是否诚实。

<?php
$dbhost="localhost"; 
$username="v22comp_B09052"; 
$password="-"; 
$db="v22comp_B09051-12-13"; 
$table="secrets"; 

// Connect to the database
mysql_connect("$dbhost", "$username", "$password") or die ("Can not connect to the database"); 
mysql_select_db("$db") or die ("Database is not selectable");

//Post input
$inputusername=$_POST['uid']; 
$inputpassword=$_POST['upassword']; 

//Check input
$sql="SELECT * FROM $table WHERE username='$inputusername' and password='$inputpassword'";
$sqlop=mysql_query($sql);

//If a row matches, output a string informing the user that they are logged in. If not, output a string informing them that they are not
$rowmatch=mysql_num_rows($sqlop);
if($rowmatch==1)
{
echo "You are now logged in";
}
else 
{
echo "Invalid ID or password";
}
?>
4

2 回答 2

0

你是对的,查询有问题。当查询出错时,它返回 false,因此返回布尔错误。

于 2013-10-08T22:38:53.923 回答
0

从我的角度来看,SQL 语句中存在错误。这就是为什么它不返回结果集的资源,而是一个假定的布尔值“假”。也许您忘记创建您尝试从中选择数据的表?

于 2013-10-08T22:39:07.640 回答