this code wont insert user save data into the sql database


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

function InsertUser(){
    global $con;
    //if sign up button is pressed
        $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>";
        //password properties string length 

            echo "<script>alert('Password should be minimum 8 characters')</script>"; 
        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);

                    echo "<script>alert('Registration Successfull!')</script>";

2 answers

  • answered 2018-05-16 04:37 Rahul Shrivastava

    i think the mistake in your query.

    "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')";

    check this one last login with your tabel field. i think it could be.


  • answered 2018-05-16 05:29 lopamudra

    The mistake is in your query

    cant give a column name like "last login"

    Remove the space between and try to change the column name of "status" to anything else