我有这些代码,它给了我一个错误“警告:mysql_num_rows() 期望参数 1 是资源”:
PHP:
<?php
@error_reporting(0);
@session_start();
@include("sql.php");
$log_error = "";
if(isset($_POST['send'])) {
$user = protect($_POST['username']);
$pass = protect($_POST['password']);
$q = mysql_query("SELECT * FROM login WHERE name = '".$user."' and pass = '".$pass."'",$sqlc);
$count = mysql_num_rows($q);
if($count > 0) {
$_SESSION['username'] == $user;
header('Location: index.php');
$log_error = "0";
} else {
$log_error = "1";
}
}
?>
HTML:
<table border="0">
<form action="" method="post">
<tr>
<td colspan="2" style="width:100%;"><span>Login</span></td>
<tr>
<tr>
<td>Username:</td>
<td><input type="text" name="username" value="" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" value="" /></td>
</tr>
<tr>
<td colspan="2" style="width:100%;"><input type="submit" name="send" value="Login" /></td>
</tr>
</form>
</table>
和 SQL 连接(sql.php):
<?php
$Host = 'localhost';
$User = 'dash_sys1';
$Pass = '123456Ben';
$DB = 'dash_sys1';
$sqlc = mysql_connect($Host,$User,$Pass) or die(mysql_error());
mysql_select_db($DB) or die(mysql_error());
function protect($str) {
return htmlspecialchars(mysql_real_escape_string(trim($str)));
}
?>
它给了我这个错误:警告:mysql_num_rows() 期望参数 1 是资源,在第 11 行的 C:\wamp\www\cms\admin\login.php 中给出的布尔值
我做错了什么?