dongyun6835 2012-03-30 05:52
浏览 28
已采纳

这个PHP / MySQL代码有什么问题?

        if(!empty($username) && !empty($email) && !empty($password) && !empty($confirm_password)){
        $username = htmlentities($username);
        $username = stripslashes($username);
        $username = strip_tags($username);
        $username = mysql_real_escape_string($username);
        $username = preg_replace("[^A-Za-z0-9]", "", $username);

        $email = htmlentities($email);
        $email = stripslashes($email);
        $email = strip_tags($email);
        $email = mysql_real_escape_string($email);
        $email = preg_replace("[^A-Za-z0-9]", "", $email);

        if(strstr($email, "@") && strstr($email, ".")) {
            require("$baseURL/scripts/connect.php");
            $checkemail = mysql_query("SELECT * FROM users WHERE email='$email'") or die(mysql_error());
            $numrows_checkemail = mysql_num_rows($checkemail);
            if($numrows_checkemail > 0) {
                require("$baseURL/scripts/connect.php");
                $checkusername = mysql_query("SELECT * FROM users WHERE username='$username'") or die(mysql_error());
                $numrows_checkusername = mysql_num_rows($checkusername);
                if($numrows_checkusername > 0) {
                    if($password == $confirm_password) {
                    $hashpass = md5(md5($password));
                        //All set to insert into the db
                        require("$baseURL/scripts/connect.php");
                        mysql_query("INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$hashpass')") or die(mysql_error());

                        $this->noticeMsg = "You have been signed up successfully!";
                    } else {
                        $this->errorMsg = "Uh-oh, looks like your passwords do not match!";

                    }
                } else {
                    $this->errorMsg = "Oops, looks like that username is already in use! Please pick a different username.";

                }
            } else {
                $this->errorMsg = "That email is already in use, please sign up with another email.";

            }
        } else {
            $this->errorMsg = "Please enter a valid email address!";

        }
    } else {
        $this->errorMsg = "Please fill in all the fields!";

    }

The error I keep getting is "That email is already in use, please sign up with another email." even though the right file is being "required" and is connected to the database properly. The problem is most likely at the $numrows_checkemail part because when I use if($numrows_checkemail == 0) it works just fine. Why won't the ">" symbol work? Am I doing something wrong? Thank you

  • 写回答

2条回答 默认 最新

  • dongle7553 2012-03-30 05:56
    关注

    if($numrows_checkemail > 0) will return true only if $numrows_checkemail is bigger than 0.
    You need to check for $numrows_checkemail == 0 or empty($numrows_checkemail)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题