everything on my form is working i need to reorder the if, else if and else statement to work likes this:
if user name = already taken username reject adding data to database and show message
else if = username contains an @ reject adding data to database and show message
else = submits data to database, send user to verification page and send a email with a verification code:
if you could leave a comment with the readjusted code would be much appreciated as i need it to be done for Thursday:
<?php
session_start();
// connect to database
$db = mysqli_connect("localhost", "root", "", "authentication")
or die('Sorry the Database is not Available<br />');
$username = "";
$password = "";
$email = "@";
$query = mysqli_query ($db, "SELECT * FROM customers WHERE username='$username'");
if (isset($_POST['register_btn']))
{
mysqli_num_rows($query) > 0;
echo "Username is already in use!";
}
else if( ! filter_var($email,FILTER_VALIDATE_EMAIL ) )
{ // "FILTER_VAR" RETURNS THE EMAIL (STRING) IF IT WAS VALID, failed!
echo "Username rejected (don't enter your email as username)";
}
else {
$username = mysqli_real_escape_string($_POST['username']);
$password = mysqli_real_escape_string($_POST['password']);
$email = mysqli_real_escape_string($_POST['email']);
// creates username
$password = password_hash($password); //hash password before storing for security purposes
$sql = "INSERT INTO customers(username, password, email) VALUES('$username', '$password', '$email')";
mysqli_query($db, $sql);
echo("location: verification.php"); //redirect to home page
}
?>
Aucun commentaire:
Enregistrer un commentaire