PHP注册没有将新用户插入表中

时间:2016-03-01 20:14:56

标签: php mysql database registration

我正在关注一个教程,我遇到了一个问题,我可以填写我的注册表单,但我的信息没有保存到数据库表中。我的所有代码都与教程相同。我错过了什么吗?

显然它与我的$ insert变量有关,但我无法弄清楚它是什么。

if(isset($_POST['register'])) {
        $user_name = mysqli_real_escape_string($con, $_POST['user_name']);      
        $user_pass = mysqli_real_escape_string($con, $_POST['user_pass']);
        $user_email = mysqli_real_escape_string($con, $_POST['user_email']);
        $user_country = mysqli_real_escape_string($con, $_POST['user_country']);
        $user_number = mysqli_real_escape_string($con, $_POST['user_number']);
        $user_address = mysqli_real_escape_string($con, $_POST['user_address']);
        $user_gender = mysqli_real_escape_string($con, $_POST['user_gender']);
        $user_b_day = mysqli_real_escape_string($con, $_POST['b_day']);

        $user_image = $_FILES['user_image']['name'];
        $user_tmp = $_FILES['user_image']['tmp_name'];

        if($user_address=='' OR $user_country=="" OR $user_image=="" OR $user_gender=='') {
            echo "<script>alert('Please fill all the fields.')</script>";
            exit();
        }

        if(!filter_var($user_email, FILTER_VALIDATE_EMAIL)) {
            echo "<script>alert('Your email is not valid.')</script>";
            exit();
        }
        $sel_email = "SELECT * FROM register_user WHERE user_email='" . $user_email . "';";
        $run_email = mysqli_query($con, $sel_email);        

        $check_email = mysqli_num_rows($run_email);

        if($check_email==1) {
            echo "<script>alert('This email is already registered. Please choose another.')</script>";
            exit();
        }

        else {
            $_SESSION['user_email'] = $user_email;

            move_uploaded_file($user_tmp, "images/$user_image");

            $insert = "INSERT INTO register_user (user_name, 
                                                user_pass, 
                                                user_email, 
                                                user_country, 
                                                user_number, 
                                                user_address, 
                                                user_gender, 
                                                user_b_day, 
                                                user_image, 
                                                register_date) 
                        VALUES ('$user_name', 
                                '$user_pass', 
                                '$user_email', 
                                '$user_country', 
                                '$user_number', 
                                '$user_address', 
                                '$user_gender', 
                                '$user_b_day', 
                                '$user_image', 
                                 NOW())";

            mysqli_query($con, $insert);

            echo "<script>alert('Registration successful.')</script>";
            echo "<script>window.open('home.php', '_self' )</script>";
        }
    }

1 个答案:

答案 0 :(得分:2)

如果您没有错误消息,请尝试以下操作:

   $insert = "INSERT INTO register_user (user_name, 
                                                user_pass, 
                                                user_email, 
                                                user_country, 
                                                user_number, 
                                                user_address, 
                                                user_gender, 
                                                user_b_day, 
                                                user_image, 
                                                register_date) 
                        VALUES ('".$user_name."', 
                                '".$user_pass."', 
                                '".$user_email."', 
                                '".$user_country."', 
                                '".$user_number."', 
                                '".$user_address."', 
                                '".$user_gender."', 
                                '".$user_b_day."', 
                                '".$user_image."', 
                                 NOW())";