简体   繁体   中英

php mysql query not being sent to database

Hi i have written this function to register users on my site. it was all working fine until recently the only change i have done is added extra columns into the table could this have an effect on the way i need to write this function?

function register($link){
    $username = mysqli_real_escape_string($link, $_POST['username']);
    $email = mysqli_real_escape_string($link, $_POST['email']);
    $password = mysqli_real_escape_string($link, $_POST['password']);
    $password2 = mysqli_real_escape_string($link, $_POST['password2']);
    if($password == $password2){
        $password= md5($password);
        $sql = "INSERT INTO users(UserName,email,password)VALUES('$username','$email','$password')";
        mysqli_query($link,$sql);
        $_SESSION['message'] = "You are now registered";
        $_SESSION['username'] = $username;
        header("location: index.php");
    }else{
        $_SESSION['message'] = "Passwords do not match";
    }
}

It will have an effect if the columns are set-up to be NON NULL. If you aren't sure, you can check the table definition with describe in a mysql console.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM