I've made a register user script and it works. When I add an if statement to see if the user was added so I can send them a confirmation email it stops working. So the first three lines add the user to the database but after that (The code in the comments) makes it no longer work.
$confirm_code = rand();
$sql = "INSERT INTO users (firstname, lastname, username, password, email, confirm_code) VALUES ('$firstname','$lastname','$username','$encrypted_password','$email', '$confirm_code')";
$new_user = mysqli_query($conn, $sql);
/*
if ($new_user) {
header('Location: ../accepted.php?usersucess');
$message =
"
Confirm Your Email
Click the link below to activate your account
http://www.generationdiary.com/email_confirm.php?username=$username&code=$confirm_code
";
$mail=mail($email, "Generation Diary Confirm", $message);
if ($mail){
header('Location: ../accepted.php');
}else{
header('Location: ../accepted.php?failedmail');
}
}
else {
header('Location: ../accepted.php?failedusersubmit');
}
*/