Created
July 16, 2020 08:24
-
-
Save Alphajeez96/351aedd745a6bd3a744b11c7e5225882 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//process.php | |
if ($_SERVER["REQUEST_METHOD"] == "POST") {//Check it is coming from a form | |
$u_email = $_POST["user_email"]; //set PHP variables like this so we can use them anywhere in code below | |
//print output text | |
print "Hello!, we have received email ". $u_email; | |
print "We will contact you very soon!"; | |
}; | |
// Remove all illegal characters from email | |
$u_email = filter_var($u_email, FILTER_SANITIZE_EMAIL); | |
// Validate e-mail | |
if (filter_var($u_email, FILTER_VALIDATE_EMAIL)) { | |
echo("$u_email is a valid email address"); | |
$host ='localhost'; | |
$dbUsername='root'; | |
$dbPassword =''; | |
$dbname='users_data'; | |
//connection created here | |
$conn = new mysqli($host,$dbUsername,$dbPassword, $dbname); | |
if(mysqli_connect_error()){ | |
die('connect Error('.myqli_connect_errno().')' . mysqli_connect_error()); | |
} else{ | |
$SELECT = " SELECT email from users_data where email = ? Limit:1"; | |
$INSERT ="INSERT into users_data (u_email) values (?)"; | |
$stmt =$conn->prepare($SELECT); | |
$stmt ->bind_param("s", $u_email); | |
$stmt ->execute(); | |
$stmt ->bind_result($u_email); | |
$stmt ->store_result(); | |
$rnum = $stmt->num_rows; | |
if($rnum ==0) { | |
$stmt->close(); | |
$stmt = $conn->prepare($INSERT); | |
$stmt->bind_param( "ssssil", $u_email); | |
$stmt->execute(); | |
echo 'new record succ3ssfully'; | |
} | |
else { | |
echo 'someone has this email'; | |
} | |
$stmt->close(); | |
$conn->close(); | |
} | |
} else { | |
echo("$u_email is not a valid email address"); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment