我正在设置此时事通讯订阅表格以与我的数据库进行通信,但在发送信息(电子邮件)之前,我只想验证它。但是,当我输入错误或空数据时,它会显示两条错误消息。我不是 PHP 方面的专家,但似乎我缺少一些右括号之类的东西。我现在已经摆弄了一段时间没有成功,所以我再次向你们寻求帮助:)
<?php
$host = "XXX";
$username = "name";
$password = "XXX";
$database = "base";
$connect = @mysql_connect($host, $username, $password) or die (@mysql_error());
$selectdb = @mysql_select_db($database, $connect) or die (@mysql_error());
if(isset($_POST['submit'])){
$email = $_POST['email'];
if(empty($email)){
echo "Hmm, you did not anything..";
}
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
echo "This email not valid";
}
else{
@mysql_query("INSERT INTO newsletters SET email='$email'");
echo "Thanks you";
}
}
?>
谢谢!!