GregHBushnell GregHBushnell - 2 months ago 5
MySQL Question

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

Answer

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.

Comments