我正在尝试制作一个脚本,1)检查数据库中是否已经存在具有给定电子邮件地址的条目,如果不存在 2)用新条目填充数据库。
这是我目前拥有的代码:
$result = mysql_query("SELECT * FROM cbsclassy WHERE email = '$email' LIMIT 1");
$num_rows = mysql_num_rows($result);
if ($num_rows > 0) { echo "It seems that you're already participating. It is
only allowed to make one entry into the competition. <a href=index.html>Click to
return to the previous page</a>.";
}
else { $sql="INSERT INTO cbsclassy (name, email, answer) VALUES
('$name','$email','$answer')";
if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error());
}
echo "You're now participating in the contest. The winners will be
notified directly via email. Good luck! <a href=index.html>Click
to return to the previous page</a>.";
}
该脚本在填充数据库时运行良好,但是如果电子邮件地址已存在于数据库中,它就无法捕获。谁能发现问题?