我正在尝试用PHP创建一个投票系统。除了创建一个带有'USER'和'PASS'作为包含登录信息的字段的标准表外,我创建了另一个包含字段的表:'USER'和'CHECK',其中'CHECK'是二进制INT,默认值为“0 ”。但是当学生投票时,“检查”字段会更新为“1”。
我设计的登录脚本首先检查“USER”和“PASS”中的记录,然后检查“USER”和“CHECK”表中的另一条记录,默认值为“0”到允许投票。如果为“1”,则重定向到“AlreadyVoted.htm”页面。
<?php
session_start();
$_SESSION['StudentID']=$_POST['UserID'];
include 'db_conneck.php';
$studentid=mysql_real_escape_string($_POST['UserID']);
$userpass=mysql_real_escape_string($_POST['LogPass']);
$sql="SELECT * FROM user_login WHERE studentid='$studentid' and password='$userpass'";
$sql1="SELECT * FROM check_login WHERE studentid='$studentid' and check='0'";
$sql2="SELECT * FROM check_login WHERE studentid='$studentid' and check='1'";
$result=mysql_query($sql);
$result1=mysql_query($sql1);
$result2=mysql_query($sql2);
$count=mysql_num_rows($result);
$count1=mysql_num_rows($result1);
$count2=mysql_num_rows($result2);
if ($count==1 and $count1==1){
header ("location:FirstVote.php");
}
else if ($count==1 and $count2==1){
header ("location:AlreadyVoted.html");
}
else {
echo "Information Not On Database";
}
exit()
?>
但是我收到此错误
警告:mysql_num_rows()要求参数1为resource,boolean 在第13行的C:\ xampp \ htdocs \ xampp \ FirstVotePage \ LoginCombo.php中给出
警告:mysql_num_rows()要求参数1为resource,boolean 在第14行的C:\ xampp \ htdocs \ xampp \ FirstVotePage \ LoginCombo.php中给出 信息不在数据库
答案 0 :(得分:1)
$result=mysql_query($sql) or die(mysql_error());
$result1=mysql_query($sql1) or die(mysql_error());
$result2=mysql_query($sql2) or die(mysql_error());
注意:不推荐使用mysql扩展程序,将来会将其删除。
答案 1 :(得分:1)
CHECK
reserved keyword你应该通过反引号来逃避它。
改为使用这些查询。
$sql1="SELECT * FROM check_login WHERE studentid='$studentid' and `check`='0'";
$sql2="SELECT * FROM check_login WHERE studentid='$studentid' and `check`='1'";
答案 2 :(得分:0)
查询中存在问题,尝试回显查询,然后尝试在数据库中手动执行。
您的查询返回布尔值false而不是资源。
答案 3 :(得分:0)
注意:强> 我仍然感到惊讶的是,一些PHP程序员仍在使用或与mysql_error()结合使用或将其作为示例代码,黑客因为信息泄漏而喜欢它......