gpt4 book ai didi

php - 如何检查电子邮件地址是否存在。验证

转载 作者:可可西里 更新时间:2023-11-01 07:33:36 26 4
gpt4 key购买 nike

我似乎不知道如何检查我的数据库中是否存在电子邮件。目前,用户使用他们的电子邮件地址使用密码登录我的网站,但目前用户可以使用同一电子邮件地址注册多次,这会导致我的网站出现大问题。已经做了一些研究,但似乎无法解决。

谁能帮帮我?

<?php       

if(isset($_POST['add']))
{
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'pass';
$db = "db";
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not send your enquiry at this time please try again later.');
}


$phone = mysql_real_escape_string((string)$_POST['phone']);
$email = mysql_real_escape_string((string)$_POST['email']);
$password = mysql_real_escape_string((string)$_POST['password']);
$firstname = mysql_real_escape_string((string)$_POST['firstname']);
$surname = mysql_real_escape_string((string)$_POST['surname']);
$country = mysql_real_escape_string((string)$_POST['country']);
$nationality = mysql_real_escape_string((string)$_POST['nationality']);
$yearofbirth = mysql_real_escape_string((string)$_POST['yearofbirth']);
$profession = mysql_real_escape_string((string)$_POST['profession']);
$status = mysql_real_escape_string((string)$_POST['status']);
$membertype = 'Registered';
$dateregistered = mysql_real_escape_string((string)$_POST['dateregistered']);
$agreedtoterms = mysql_real_escape_string((string)$_POST['agreedtoterms']);

$sql = "INSERT INTO members
(phone, email, password, firstname, surname, country, nationality, yearofbirth, profession, uniquepin, status, membertype, dateregistered, agreedtoterms)
VALUES('$phone', '$email', '$password', '$firstname','$surname','$country','$nationality','$yearofbirth','$profession','$uniquepin','$status','$membertype','$dateregistered', '$agreedtoterms')";


mysql_select_db($db);
$retval = mysql_query( $sql, $conn )or die(mysql_error());

?>

最佳答案

您可以使 email 列具有唯一约束 - 然后在尝试插入时查询将失败。

你也可以直接查询....

SELECT `email`
FROM `members`
WHERE `email` = '$email'
LIMIT 1

如果您得到结果,则该电子邮件存在。

关于php - 如何检查电子邮件地址是否存在。验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6087282/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com