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条)

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线