此代码不会将用户保存数据插入sql数据库

时间:2018-05-16 04:21:10

标签: php sql

<?php

$con = mysqli_connect("localhost","root","","social_network") or die("Connection was not established");

function InsertUser(){
    global $con;
    //if sign up button is pressed
    if(isset($_POST['sign_up'])){
        $name = $_POST['u_name'];
        $pass = $_POST['u_pass'];
        $email = $_POST['u_email'];
        $country = $_POST['u_country'];
        $gender = $_POST['u_gender'];
        $b_day = $_POST['u_birthday'];
        $name = $_POST['u_name'];
        $date = date("d-m-y");
        $status = "unverified";
        $posts = "No";
        //checks if the email already existist in the system
        $get_email = "select * from users where user_email='$email'";
        $run_email = mysqli_query($con,$get_email);
        $check = mysqli_num_rows($run_email);
        //if email validation
        if ($check==1) {
            echo "<script>alert('This email is already registered!, Try another one')</script>";
            exit();
        }
        //password properties string length 
        if(strlen($pass)<8){

            echo "<script>alert('Password should be minimum 8 characters')</script>"; 
            exit();
        }
        else {
            //inserting user input into the database
            $insert = "INSERT INTO users (user_name,user_pass,user_email,user_country,user_gender,user_dob,user_image,register_date,last login,status,posts) VALUES ('$name','$pass','$email','$country','$gender','$b_day','default.jpg','$date','$date','$status','$posts')";

            $run_insert = mysqli_query($con,$insert);

                if($run_insert){
                    echo "<script>alert('Registration Successfull!')</script>";
                } 
            }
        }
    }
?>

1 个答案:

答案 0 :(得分:0)

错误在于您的查询

  

无法提供类似“上次登录”的列名

删除它们之间的空格并尝试将“status”的列名更改为其他任何内容

相关问题