首页 > 解决方案 > 如果 sql 列具有特定值,则重定向

问题描述

我是 php 新手,所以任何帮助将不胜感激。我有一个为用户创建帐户的页面,在创建帐户时,有一个选择字段,其中包含三个特定值,可以从“notfcode”“tfail”**“tfcode”中选择。

还有另一个页面 check.php 允许用户检查他的 ttype。我想要做的是让页面尝试读取 ttype 的 sql 表行,如果用户帐户上的值是“notfcode”,它将重定向到 notfcode.php 页面,如果它的“tfail”重定向到 tfail。 php 并且如果它的“tfcode”它停留在页面上。下面是我一直在努力但没有成功的代码。

<?php session_start();
include_once ('session.php');
require_once 'class.user.php';
if(!isset($_SESSION['acc_no'])){
header("Location: login.php");
exit(); 
}
$reg_user = new USER();

$stmt = $reg_user->runQuery("SELECT * FROM account WHERE acc_no=:acc_no");
$stmt->execute(array(":acc_no"=>$_SESSION['acc_no']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$email = $row['email'];

$temp = $reg_user->runQuery("SELECT * FROM transfer WHERE email = '$email' ORDER BY id DESC LIMIT 1");
$temp->execute(array(":acc_no"=>$_SESSION['acc_no']));
$rows = $temp->fetch(PDO::FETCH_ASSOC);

$transfertype = $row['ttype'];   

if(isset($_SESSION['acc_no'])){
    $transfertype = $row['ttype'];
    if($transfertype == nocodetf){
        header("Location: nocodetf.php");
    }
    elseif($transfertype == tfail){
        header("Location: nocodetf.php");
    }
    else {
        header("Location: check.php");
    }
}


include_once ('counter.php');
?>

当页面加载时,它什么也不做,没有我想要的重定向。指向正确方向的指针将不胜感激。

标签: phpsql

解决方案


这是字符串。

if($transfertype == "nocodetf"){ 或者 if($transfertype == 'nocodetf'){

激活 PHP 错误报告比 PHP 向您显示这一点。

error_reporting(E_ALL);
ini_set('display_errors', 1);

$transfertype = "foo";

if ($transfertype == nocodetf) {  # <-- as you did it
//...
}

// <b>Warning</b>:  Use of undefined constant nocodetf - assumed 'nocodetf' (this will throw an Error in a future version of PHP) in ...

推荐阅读