php - 如果 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');
?>
当页面加载时,它什么也不做,没有我想要的重定向。指向正确方向的指针将不胜感激。
解决方案
这是字符串。
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 ...
推荐阅读
- python - 如何基于另一列条件的相似列合并两个数据框?
- javascript - 如何在hmtl中制作颜色选择线
- sql - HiveQL - 窗口上多列的 first_value
- java - 您对 Android 应用的支持有多远?
- ruby-on-rails - 从散列中的散列中的散列中检索值在散列中的数组中
- android - 颤振:“无法解析符号'@android:color/white'”,同时更改启动画面
- excel - 用于在多张纸上循环的范围内查找最大值和最小值的 VBA 代码
- python - 当我运行 Flask 时,它显示错误:ModuleNotFoundError: No module named 'werkzeug.contrib'。谁能帮我这个?
- javascript - 为什么不超过 PHP 行限制时 JS 整数不递增?
- r - 为 OLS 回归创建滚动估计窗口