【问题标题】:Trying to update database table content value尝试更新数据库表内容值
【发布时间】:2020-05-03 03:25:16
【问题描述】:

我正在尝试更新我的数据库表内容中“已验证”的值。 “已验证”内容设置为“假”我正在使用 PHPMailer 发送电子邮件验证链接,一旦用户单击按钮/链接,我想将已验证表从“假”更改为“真”。这是我正在使用的代码,电子邮件发送得很好,但是单击链接时它不会更新表格。 (我删除了敏感信息)

<?php


require 'controllers/authController.php';

require_once 'db/config.php';

$name = $_SESSION['username'];
$email = $_SESSION['email'];



use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

$mail = new PHPMailer(true);

try{
// Server Settings
$mail->SMTPDebug = 1;
$mail->isSMTP();
$mail->Host = '';
$mail->SMTPAuth = true;
$mail->Username = '';
$mail->Password = '';
$mail->SMTPSecure = '';
$mail->Port = ;

// Recipients
$mail->setFrom('', '');
$mail->addAddress($email);

$body = '<!DOCTYPE html>
         <html lang="en">
         <head>
            <meta charset="UTF-8">
         </head>
         <body>
         <form method="post">
         <div class="wrapper">
          Hi, &nbsp;' . $name . '! <p>Please click the link below to verify your account.</p><br>
         <button class = btn btn-primary verifylink><a href="localhost/gitscripts/home.php">Verify Email</a></button>
         </form>';

if(isset($_GET['verifylink'])){
    $verified = true;

    $sql = "UPDATE users SET verified=[true]";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param('b', $verified);
}



// Content
$mail->isHTML(true);
$mail->Subject = 'Verify Your Email';
$mail->Body = $body;
$mail->AltBody = strip_tags($body);

$mail->send();
echo 'Message has been sent';
} catch (Exception $e){
echo 'Message could not send';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
?>

这是我曾经尝试完成的特定代码行...

if(isset($_GET['verifylink'])){
    $verified = true;

    $sql = "UPDATE users SET verified=[true]";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param('b', $verified);
}

【问题讨论】:

  • 你确定要这样做"UPDATE users SET verified=true";吗?您正在更改 ALL 个用户

标签: php database mysqli phpmailer


【解决方案1】:

如果verified 属于bit 或boolean 类型,则使用以下内容:

UPDATE users SET verified = 1 -- Alternatively, set to 0 for false

如果您真的不想运行硬编码查询,则需要在查询中使用? 运算符,它将替换为您在$stmt-&gt;bind_param('b', $verified) 中提供的值:

UPDATE users SET verified = ?

Check this question查看完整集成

【讨论】:

  • if(isset($_GET['verifylink'])){ $verified = true; $sql = "更新用户设置验证=?"; $stmt = $conn->prepare($sql); $stmt->bind_param('b', $verified); } 我刚试过这个,它仍然没有更新数据库值。
猜你喜欢
  • 2013-04-05
  • 1970-01-01
  • 2023-01-29
  • 2018-05-05
  • 1970-01-01
  • 1970-01-01
  • 2023-03-28
  • 2012-06-05
  • 2016-12-29
相关资源
最近更新 更多