验证无效

时间:2017-09-25 12:42:58

标签: php

所以我试图通过电子邮件验证用户(发送完美),但是当他们点击链接时会显示“未插入”。这显然是因为我在插入区域写错了,但我不太确定它可能是什么。这是我的剧本:

<?php
session_start();
require 'connect.inc.php';


$Username = $_GET['usr'];
$Code = $_GET['verify'];
$One = '1';

$sql = "SELECT Username, `VerficationCode`, `Verified` FROM user WHERE `Username`='$Username'";
$result = $con->query($sql);

if ($result->num_rows > 0) {

    while($row = $result->fetch_assoc()) {

        $ActualCode = $row['VerficationCode'];

        if ($Code == $ActualCode) {

            $confirm = "INSERT INTO user (VerficationCode) VALUES ('$One') WHERE `Username` = '$Username'";
            if(!mysqli_query($con,$confirm)){
                $_SESSION['failed'] = 'Oops! Something went wrong. Please try again.';
                echo 'not inserting.';
            } else {
                header ('Location: home.php');
                $_SESSION['verified'] = 'Successfully verified.';
            }
        } else {

            $_SESSION['verified'] = 'Unsuccessfully verified.';
            header ('Location: index.php');
            echo 'unsuccessful';
        }
    }
} else {
    $_SESSION['failed'] = 'Oops! Something went wrong. Please try again.';
    header ('failed.php');
}


?>

这是我的connect.inc.php脚本:

<?php

$con = mysqli_connect("localhost", "root", "", "users");

?>

修改:验证链接如下所示:http://********.com/home.php?verify=friendov59c806e6bfc57TimerHotel20001&usr=TimerHotel

1 个答案:

答案 0 :(得分:0)

而不是

"INSERT INTO user (VerficationCode) VALUES ('$One') WHERE `Username` = '$Username'"

使用

"UPDATE user SET `VerficationCode`='$One' WHERE `Username` = '$Username'"