检查电子邮件是否已存在..
$query="SELECT email FROM user_info WHERE email='".$Email."'";
$result=mysql_query($query) or die("email cannot be added".mysql_error());
if($row=mysql_fetch_array($result))
{
die(" Sorry that user " .$email. " already exists ! <br>");
}
请给我简单的程序
答案 0 :(得分:1)
$query = "SELECT email FROM user_info WHERE email = '" . $email . "'";
$result = mysql_query($query);
if(mysql_fetch_array($result) !== false) {
die("Sorry that user " . $email . " already exists ! <br>");
}
您还应该知道,PHP变量区分大小写,因此如果未定义其中一个,则使用$Email
和$email
将失败。
答案 1 :(得分:0)
尝试使用mysql_num_rows
$query="SELECT email FROM user_info WHERE email='".$email."'";
$result=mysql_query($query) or die("email cannot be added".mysql_error());
if(mysql_num_rows($result) > 0)
{
die(" Sorry that user " .$email. " already exists ! <br>");
}