0
我昨天晚上在我添加到我的數據庫之前試圖檢查電子郵件域名,例如我想add @ hotmail.com,如果任何一個寫入hotmail.c我必須拒絕將它添加到我的數據庫中。如何檢查電子郵件在PHP?
這是我的代碼的PHP:
<?PHP
if(isset($_POST['name']) && isset($_POST['email']) && isset($_POST['password'])){
include_once("connection12.php");
$email1 = $_POST['email'];
$SQL = "SELECT email FROM registration WHERE email = '$email1'";
$result = mysql_query($SQL);
$num_rows = mysql_num_rows($result);
if ($num_rows > 0) {
echo "email already taken";
}
else{
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
mysql_query("insert into registration(name, email, password) values('$name', '$email', '$password')");
echo "Data Submit Successfully";
}
}
?>
U van使用FILTER_VALIDATE_EMAIL'if(!filter_var($ email,FILTER_VALIDATE_EMAIL)=== false){ echo(「$ email is a valid email address」);} else {echo「not valid」;}' – devpro
你的代碼是打開的SQL注入使用準備好的語句,並注意mysql_ *關閉在PHP 7 – devpro
我希望你現在得到了解決方案 – devpro