数据库不会更新(双重选择邮件列表)

时间:2018-01-03 22:16:56

标签: php mysql

非常新的PHP,并且在邮件列表中使用双重选择。我在这里找到了这段代码:http://www.sitepoint.com/forums/showthread.php?632689-Guide-to-creating-a-double-opt-in-email-list&s=560d4d5d106fde7ccc1a53b507c436cd&p=4350152&viewfull=1#post4350152 并且直到我点击电子邮件中的链接才使其工作,由于某种原因它不会将数据库中的状态更新为“已确认”(它表示“抱歉,帐户未经验证”)。

我无法用我的基本知识找到错误,谢谢一些帮助! 非常感谢 JD

signup.php:

<?php
if(true === array_key_exists('submit', $_POST))
{
require("connect.php");

$rResult = mysqli_query($conn,
    sprintf(
        "INSERT INTO newsletter2 (email, status)VALUES('%s', 'pending')",
        $_POST['email']
    )
);
mail(
    $_POST['email'],
    'Subscriber Confirmation',
    sprintf(
        'Thankyou, please visit http://****.com/newsletter2/confirmSignUp.php?key=%s to confirm your subscription.',
        sha1($_POST['email'])
    ),
    null,
    null
);
echo 'Thankyou, please check the provided email for a link to confirm your subscription.';
exit;
}
?>

confirmSignUp.php:

<?php
if(true === array_key_exists('key', $_GET))
{
require("connect.php");

$rResult = mysqli_query($conn,
    sprintf(
        "UPDATE newsletter2 SET status = 'confirmed' WHERE email = SHA1('%s')",
        $_GET['key']
    )
);
if(mysqli_affected_rows($conn) > 0)
{
    echo 'Thankyou, email confirmed';
}
else
{
    echo 'Sorry, account unvalidated.';
}
exit;
}
?>

1 个答案:

答案 0 :(得分:0)

signup.php

$rResult = mysqli_query($conn,
    sprintf(
        "INSERT INTO newsletter2 (email, status, authkey)VALUES('%s', 'pending', '%s')",
        $_POST['email'],
        sha1($_POST['email']) 
    )
);

confirmSignUp.php:

$rResult = mysqli_query($conn,
    sprintf(
        "UPDATE newsletter2 SET status = 'confirmed' WHERE authkey = '%s'",
        $_GET['key']
    )
);