Php 数据库未更新值,空白页

Php 数据库未更新值,空白页,php,mysql,pdo,Php,Mysql,Pdo,好的,我又来了。我问了一个类似的问题,但这里的区别是没有形式 我正在尝试验证用户帐户,因此我将验证链接发送到用户的电子邮件地址,当他们单击该链接时,我需要数据库将数据库中的is_active列更新为1,并清除URL的令牌 以下是当用户单击链接时应执行的php代码: require("../config.php"); //connects to the database $sql = "SELECT activation_expiration, is_active FROM users WHER

好的,我又来了。我问了一个类似的问题,但这里的区别是没有形式

我正在尝试验证用户帐户,因此我将验证链接发送到用户的电子邮件地址,当他们单击该链接时,我需要数据库将数据库中的is_active列更新为1,并清除URL的令牌

以下是当用户单击链接时应执行的php代码:

require("../config.php"); //connects to the database

$sql = "SELECT activation_expiration, is_active FROM users WHERE activation = :token";
$stmt = $db->prepare($sql);
$stmt->bindParam(":token", $_GET['token']);
$stmt->execute();
$result = $stmt->fetch();

// Is the user active?
$is_active = $result['is_active'];

//Get Token Expiration Date
$tokenExpiration = $result['activation_expiration'];

// Get current DateTime
$now = new DateTime();
$currentDate = $now->format('Y-m-d h:i:s a') . "\n";

// This function will update the user to active
function updateActivation($dbHandler){
if($tokenExpiration > $currentDate) {
if(isset($_GET['email']) && !empty($_GET['email']) AND isset($_GET['token']) && !empty($_GET['token'])){

    $email = $_GET['email']; // Set email variable 
    $token = $_GET['token']; // Set token variable          

            $query_params = array(
                ':user' =>  $email,
                ':token' => $token,
                ':emptyToken' => '',
                ':active' => 1
            ); 

            $dbHandler->beginTransaction();
            $sql = "UPDATE users SET is_active = :active, activation_expiration = :emptytoken WHERE username = :user AND activation = :token";
            $stmt = $dbHandler->prepare($sql); 
            $result = $stmt->execute($query_params);
            $dbHandler->commit(); 

            $account_verified = 'Account verified! Please log in.';
            $_SESSION['account_verified'] = $account_verified;

            header("Location: ../index.php"); 
            die("Redirecting to index.php");    

} else {
    $dbHandler->rollback();
}
} else {
header("Location: ../forgot-password/token-expired.php"); 
die("Redirecting to token-expired.php"); 
}
}

// This will run the function if the user is not active
if($is_active === 0){
try {
    updateActivation($db);
} catch (Exception $e){
    $error =  'The following error occured: <br/>'.$e->getMessage();
}   
}elseif($is_active === 1){
echo "You have already verified your account!";
}
require(“../config.php”)//连接到数据库
$sql=“选择激活\u过期,是否从激活=:令牌的用户处激活”;
$stmt=$db->prepare($sql);
$stmt->bindParam(“:token”,$\u GET['token']);
$stmt->execute();
$result=$stmt->fetch();
//用户是否处于活动状态?
$is_active=$result['is_active'];
//获取令牌到期日期
$tokenExpiration=$result['activation\u expiration'];
//获取当前日期时间
$now=新日期时间();
$currentDate=$now->格式('Y-m-DH:i:SA')。“\n”;
//此功能将用户更新为活动状态
函数updateActivation($dbHandler){
如果($tokenExpiration>$currentDate){
如果(isset($获取['email'])和&!empty($获取['email'])和isset($获取['token'])和&!empty($获取['token'])){
$email=$_GET['email'];//设置电子邮件变量
$token=$\u GET['token'];//设置令牌变量
$query_params=数组(
':user'=>$email,
':token'=>$token,
“:emptyToken'=>”,
':活动'=>1
); 
$dbHandler->beginTransaction();
$sql=“更新用户集是\u活动=:活动,激活\u过期=:emptytoken,其中用户名=:用户和激活=:令牌”;
$stmt=$dbHandler->prepare($sql);
$result=$stmt->execute($query\u参数);
$dbHandler->commit();
$account_verified='帐户已验证!请登录';
$\u会话['account\u verified']=$account\u verified;
标题(“位置:../index.php”);
die(“重定向到index.php”);
}否则{
$dbHandler->rollback();
}
}否则{
标题(“位置:../forget password/token expired.php”);
die(“重定向到tokenexpired.php”);
}
}
//如果用户未处于活动状态,这将运行该功能
如果($is_active==0){
试一试{
更新活动(db);
}捕获(例外$e){
$error='发生以下错误:
。$e->getMessage(); } }elseif($is_active==1){ echo“您已经验证了您的帐户!”; }
我没有收到任何错误,$\u GET值存储在变量中,但由于某些原因,它没有运行update命令

所以,我的问题是,你看到我的代码中有什么错误吗? 我错过什么了吗? 总的来说,如何让更新脚本工作

编辑:示例url
http://www.mystreetlife.com/my-home/admin/users/verify.php?email=email@gmail.com&token=8d0522b85c9c16c3dfy349d02324058b


好吧,我终于让它开始工作了

我将功能代码更改为:

// This function will update the user to active
function updateActivation($dbHandler){

if($GLOBALS['tokenExpiration'] > $GLOBALS['currentDate']) {

    $email = $_GET['email']; // Set email variable 
    $token = $_GET['token']; // Set token variable
    $emptyToken = ''; // Set variable to empty the activation token in the database
    $emptyExpiration = ''; // Set variable to empty the activation expiration token in the database
    $active = 1; // Set variable to update user to active in database

    try {
            $query = "UPDATE users SET is_active = :active, activation = :emptytoken, activation_expiration = :emptyexpiration WHERE username = :user AND activation = :token";
            $stmt = $dbHandler->prepare($query);
            $stmt->bindParam(":user", $email); 
            $stmt->bindParam(":token", $token); 
            $stmt->bindParam(":emptytoken", $emptyToken);
            $stmt->bindParam(":emptyexpiration", $emptyExpiration);
            $stmt->bindParam(":active", $active);
            $stmt->execute();

            header("Location: ../index.php"); 
            die("Redirecting to index.phpp"); 
    } catch (Exception $e) {
        echo '<strong>The following error occured:</strong> '.$e->getMessage();
    }           

} else {
    header("Location: ../forgot-password/token-expired.php"); 
    die("Redirecting to token-expired.php"); 
}
}
//此函数将用户更新为活动
函数updateActivation($dbHandler){
如果($GLOBALS['tokenExpiration']>$GLOBALS['currentDate'])){
$email=$_GET['email'];//设置电子邮件变量
$token=$\u GET['token'];//设置令牌变量
$emptyToken='';//设置变量以清空数据库中的激活令牌
$EMPTYEXPTION='';//设置变量以清空数据库中的激活过期令牌
$active=1;//设置变量以将数据库中的用户更新为active
试一试{
$query=“更新用户集处于活动状态=:活动状态,激活状态=:emptytoken,激活状态=:emptyexpiration,其中用户名=:用户和激活状态=:令牌”;
$stmt=$dbHandler->prepare($query);
$stmt->bindParam(“:user”,$email);
$stmt->bindParam(“:token”,$token);
$stmt->bindParam(“:emptytoken,$emptytoken”);
$stmt->bindParam(“:emptyExportation”,$emptyExportation);
$stmt->bindParam(“:active”,“$active”);
$stmt->execute();
标题(“位置:../index.php”);
die(“重定向到index.phpp”);
}捕获(例外$e){
echo'发生以下错误:。$e->getMessage();
}           
}否则{
标题(“位置:../forget password/token expired.php”);
die(“重定向到tokenexpired.php”);
}
}
然后使用以下命令运行函数:

// This will run the function if the user is not active
if ($is_active == 0) {
try {
    updateActivation($db);
} catch (Exception $e){
    echo '<strong>The following error occured:</strong> '.$e->getMessage();
}   
}
//如果用户未处于活动状态,此操作将运行该函数
如果($is_active==0){
试一试{
更新活动(db);
}捕获(例外$e){
echo'发生以下错误:。$e->getMessage();
}   
}

您能给我们展示一个被点击的URL的例子吗?在打开
@JayBlanchard后立即将错误报告添加到文件顶部我添加了错误报告并收到了此很长的错误:
严格标准:DateTime::\uu construct():依赖系统的时区设置是不安全的。您*必须*使用date.timezone设置或date\u default\u timezone\u set()函数。如果您使用了这些方法中的任何一种,但仍然收到此警告,则很可能是您拼错了时区标识符。我们在第20行选择了“美国/纽约”作为“EDT/-4.0/DST”,而不是第20行
另外,这里有一个URL示例:`为了得到警告,您必须更改/修复php.ini中的设置并重新启动服务器。@JayBlanchard如果这是一个愚蠢的问题,很抱歉,但是我需要在php.ini中更改什么?我在这个文件中只有5行,没有一行与日期/时间有关。