我有一个用于注册表单的PHP代码,它将详细信息存储到表(temp_members_db),然后向输入的电子邮件发送确认代码。如果单击代码,则temp_members_db中的详细信息将传输到新表registered_members,如果用户登录,将从中检查登录详细信息。
问题与注册码有关,我该如何避免重复电子邮件和用户名? 我的代码是:
<?php
include('config.php');
$tbl_name=temp_members_db;
$confirm_code=md5(uniqid(rand()));
$name=$_POST['name'];
$email=$_POST['email'];
$password=$_POST['password'];
$password_confirm=$_POST['password_confirm'];
$sql="INSERT INTO $tbl_name(confirm_code, name, email, password)VALUES('$confirm_code', '$name', '$email', '$password')";
$result=mysql_query($sql);
if
($password != $password_confirm)
{
echo "Password do not match";
}
else if
($result)
{
$to=$email;
$subject="Your confirmation link here";
$header="from: Name <confirm@domain.org>";
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://mydomain@domain.org/confirmation.php?passkey=$confirm_code";
$sentmail = mail($to,$subject,$message,$header);
}
else {
echo "Email not found";
}
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "<BR/>Cannot send Confirmation link to your e-mail address";
}
?>
谢谢:D
答案 0 :(得分:0)
运行SQL以确定INSERT
之前的任何表中是否已存在名称或电子邮件到数据库中。
如果查询返回>0
,您可以显示错误消息。
例如,
SELECT COUNT(*) FROM temp_members_db, registered_members WHERE email = $email OR name = $name;