嗨,我想知道是否有人可以帮助我,我基本上有一个注册表,用户可以注册和每个注册是一个唯一的验证码生成到数据库中,并在电子邮件发送给用户时,他们注册。
我现在正在进行第二阶段的工作,用户点击他们电子邮件中的链接,然后被带到verification.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.发布于 2013-03-14 20:19:08
像这样的东西应该是有效的:
$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'];
}发布于 2013-03-14 20:25:36
首先,您应该知道mysql_*函数已经被弃用,您应该使用其他MySQL库之一,比如mysqli或PDO (它支持多种SQL库)。
其次,您应该为您选择的mysql库使用适当的转义函数。
要选择匹配的电子邮件,请使用SELECT email FROM ...
要检查结果,您可以从num_rows函数(例如,mysql库中的mysql_num_rows或mysqli中的num_rows属性)开始,查看它是否找到匹配的电子邮件地址,如果找到匹配,则获取实际的行内容以获取电子邮件。然后使用PHP向该地址发送电子邮件。
https://stackoverflow.com/questions/15408852
复制相似问题