我仍然是PHP和mySql的新手,然后我通过输入所有这些来学习,但结果是:警告:mysql_num_rows()期望参数1是资源,布尔在/home/k1424852/public_html/welcome.php中给出第15行,然后我搜索周围,但没有任何解决方案:(,我得到压力:(,请帮助...
<?php session_start();
include('config.php');?>
<html>
<head>
<title> My Data </title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php include("header.php"); ?>
<p class="welcome" id="greeting">
<?php
$usercheck=$_POST["username"];
$passcheck=$_POST["password"];
$db_query= mysql_query("SELECT * FROM users WHERE username = '".$usercheck."'");
if (mysql_num_rows($db_query) == 1){ *//<----- line 15*
$record = mysql_fetch_array($db_query);
if (md5($passcheck) == $record['password']){
echo "Welcome, ". $usercheck ."! You are now logged in.<br/>";
$_SESSION['user']= $usercheck;
$_SESSION['pass']= $passcheck;
}
else
echo "Sorry, wrong password. <br/>";
}
else
echo "Sorry, wrong username.<br/>";
?>
<a href="index.php">Click here </a>to return to the main page.
<?php include("footer.php"); ?>
</body>
</html>
非常感谢你的帮助,我真的想学习,但如果我变得虚假,就没有导师。:(谢谢。
答案 0 :(得分:0)
第14行中的dbquery失败并返回false。因此,您收到了该错误。
你应该这样检查。
$db_query= mysql_query("SELECT * FROM users WHERE username = '".$usercheck."'");
if($db_query && mysql_num_rows($db_query) == 1)