gpt4 book ai didi

php - 验证 mysql 列数据并在该行中查找匹配的电子邮件?

转载 作者:行者123 更新时间:2023-11-29 02:29:25 26 4
gpt4 key购买 nike

您好,我想知道是否有人可以帮助我,我基本上有一个注册表单,用户可以在其中注册,每次注册都会为数据库生成一个唯一的验证码,并在用户注册时通过电子邮件发送给他们。

我现在正在处理第二阶段,用户单击他们电子邮件中的链接并转到 verification.php

在此页面上,用户必须输入他们在电子邮件中发送的验证/注册码。我这里的脚本应该查找验证码并确保它与数据库中的相匹配。

我想做的是以某种方式告诉我的查询,如果验证码/注册码与我们在数据库中保存的正确,则向我们为匹配该验证码的用户保存的电子邮件地址发送一封确认电子邮件. (因此属于具有相同验证码的那一行的电子邮件。)

我的 table 是这样的

id           email               registration_code (verification code)
1 example@email.com 5093dkfd

目前我的查询搜索数据库中保存的注册码,但我不知道如何找到该注册码的匹配电子邮件并发送电子邮件。这一点我需要帮助。谁能给我指出正确的方向,

我还希望查询能够告诉用户他们是否正确输入了代码,因为它当前告诉他们他们已经正确输入了代码,即使他们没有。

/**
* ShuttleCMS - A basic CMS coded in PHP.
* Verification Code Check - Used to confirm a user's verification code
*
*/
define('IN_SCRIPT', true);
// Start a session
session_start();

//Connect to the MySQL Database
include 'includes/_config/connection.php';


/*
* Checks form field for verification code, then where verification code has email, send email to recipient
*/

if ($_POST['verificationcode']=='') {
header('Location: verification.php?err=1');
}
if(get_magic_quotes_gpc()) {
$verificationcode = htmlspecialchars(stripslashes($_POST['verificationcode']));
}
else {
$verificationcode = htmlspecialchars($_POST['verificationcode']);

}


/*
* Checks if the verification code exists and look for email in that row which belongs to that verification code to send email out.
*/

$sql = "SELECT COUNT(*) FROM ptb_registrations WHERE registration_code = '$verificationcode' AND '$verificationcode' MATCHES email";
$result = mysql_query($sql)or die('Could not find member: ' . mysql_error());

if (!mysql_result($result,0,0)>0) {
header('Location: verification.php?err=2');
}

然后我们发送一封确认邮件:

/*
* Email out the infromation
*/


(EMAIL BODY)
YOUR code was matched and you are now registered etc.

最佳答案

像这样的东西应该可以工作:

$sql = "SELECT email FROM ptb_registrations WHERE registration_code = '$verificationcode'";
$result = mysql_query($sql)or die('Could not find member: ' . mysql_error());
if (mysql_num_rows($result) == 0) {
header('Location: verification.php?err=2');
} else {
$row = mysql_fetch_array($result);
$email = $row['email'];
}

关于php - 验证 mysql 列数据并在该行中查找匹配的电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15408852/

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