嗨,我想知道是否有人可以帮助我,我基本上有一个注册表格,用户可以注册,每次注册一个唯一的验证码生成到数据库,并在电子邮件发送给用户,当他们注册。
我现在在第二阶段工作,用户单击他们的电子邮件中的链接,并被带到验证。php
在此页面上,用户必须输入他们在电子邮件中收到的验证码/注册码。我这里的脚本应该查找验证码,并确保它与数据库中的验证码匹配。我想做的是以某种方式告诉我的查询,如果验证码/注册码与我们在数据库中持有的验证码正确,则向我们为匹配该验证码的用户持有的电子邮件地址发送确认电子邮件。(因此,属于该行具有相同验证码的电子邮件。)
我的表是这样的
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'];
}
首先,您应该知道mysql_*函数已经被弃用,您应该使用其他mysql库之一,例如mysqli或PDO(它支持多种SQL风格)。
第二,你应该为你选择的mysql库使用合适的转义函数。
选择匹配的邮箱,使用SELECT email FROM ...
要检查结果,您可以从num_rows函数(例如mysql库中的mysql_num_rows
或mysqli中的num_rows
属性)开始查看是否找到匹配的电子邮件地址,然后如果找到匹配,则获取实际行内容以获取电子邮件。然后使用PHP发送电子邮件到该地址