0

我有一个注册表单的 php 代码,它将详细信息存储到表中(temp_members_db),然后向输入的电子邮件发送确认代码。如果单击该代码,则来自 temp_members_db 的详细信息将传输到一个新表 register_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

4

1 回答 1

0

运行 SQL 以确定姓名或电子邮件在INSERT进入数据库之前是否已存在于任何表中。如果查询返回,您可以显示错误消息>0

例如,

SELECT COUNT(*) FROM temp_members_db, registered_members WHERE email = $email OR name = $name;

于 2013-05-09T05:56:20.207 回答