this code wont insert user save data into the sql database

<?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>";
                } 
            }
        }
    }
?>

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.

    last_login
    

  • 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