douaoli5328 2014-11-03 00:15
浏览 90

为什么我不能使用mysql_num_rows? [重复]

On line 25 in my code, I wrote this:

$check = mysql_num_rows($u_check); 

and it gave me the error:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\Download\htdocs\hoping.php on line 25

Here is my entire code of the file:

<?php include ("./header.inc.php"); ?>
<?php
$reg = @$_POST['reg'];
$fn = "";
$ln = "";
$un = "";
$em = "";
$em2 = "";
$pswd = "";
$pswd2 = "";
$d = "";
$u_check = "";
$fn = strip_tags(@$_POST['fname']);
$ln = strip_tags(@$_POST['lname']);
$un = strip_tags(@$_POST['username']);
$em = strip_tags(@$_POST['email']);
$em2 = strip_tags(@$_POST['email2']);
$pswd = strip_tags(@$_POST['password']);
$pswd2 = strip_tags(@$_POST['password2']);
$d = date("Y-m-d");

if($reg){
if($em==$em2){
$u_check = mysql_query("SELECT username FROM test WHERE username='$un'");
$check = mysql_num_rows($u_check);
if($check == 0){
if($fn&&$ln&&$un&&$em&&$em2&&$pswd&&$pswd2){
if($pswd==$pswd2){
if(strlen($un)>25||strlen($fn)>25||strlen($ln)>25){
echo "The maximum limit for username/first name/last name is 25 characters!";
}
else
{
if(strlen($pswd)>30||strlen($pswd)<5){
echo "Your password must be between 5 and 30 characters long!";
}
else
{
$pswd =md5($pswd);
$pswd2 = md5($pswd2);
$query = mysql_query("INSERT INTO test VALUES ('', '$un', '$fn', '$ln','$em', '$pswd', '$d','0')");
die("<h2>Welcome to communicate</h2>Login to your account to get started ...");
}
}
}
else {
echo "Your passwords don't match!";
}
}
else {
echo "Please fill in all of the fields";
}
}
else {
echo "Username already taken ...";
}
}
else {
echo "Your E-mails don't match!";
}
}
if(isset($_POST["user_login"]) && isset($_POST["password_login"])) {
$user_login = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["user_login"]);
$password_login = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password _login"]);
}
?>



            <td width="40%">
            <h2>Sign Up Below!</h2>
            <form action="#" method="POST"> 
<input type="text" name="fname" size="25" placeholder="First Name" /><p />
                <input type="text" name="lname" size="25" placeholder="Last Name"/><br /><br />
                <input type="text" name="username" size="25" placeholder="Username"/><br /><br />
                <input type="text" name="email" size="25" placeholder="Email Address"/><br /><br />
                <input type="text" name="email2" size="25" placeholder="Email Address (again)"/><br /><br />
                <input type="text" name="password" size="25" placeholder="Password"/><br /><br />
                <input type="text" name="password2" size="25" placeholder="Password (again)"/><br /><br />
                <input type="submit" name="reg" value="Sign Up!">
</td>
        </tr>

    </table>
    <?php include ("./footer.inc.php"); ?>

Why is it giving me that error?

</div>
  • 写回答

2条回答 默认 最新

  • duanquanzhi5560 2014-11-03 00:28
    关注

    mysql_query returns false on error (a boolean), so maybe that is what is happening. Try and print the error if so? For example:

    $u_check = mysql_query("SELECT username FROM test WHERE username='$un'");
    if(!$u_check) {
        die('Invalid query: ' . mysql_error());
    }
    

    That may point you in the right direction. Also note mysql_query and related functions are long deprecated. You should learn how to use the mysqli* functions.

    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line