php sql值为空重定向

标签 php mysql

我有一个名为 recruiting 的数据库表,其中包含一个名为 rct_app_uidrct_app_id 的字段,如果用户没有 rct_app_id 我想要请求重定向。如果 rct_app_id 有值并且与 rct_app_uid 相同,请求将不会被重定向。

$user_id = $_SESSION['uid'];

    $sql = "SELECT * FROM recruiting WHERE rct_app_uid = $user_id";
    $result = query($sql);

    while(($row = mysqli_fetch_assoc($result))!=false){
        echo $rct_app_uid = $row['rct_app_uid'];

        if ($rct_app_uid >0){

            return true;

        } else {

            redirect(ROOT_URI);

        }
    }

最佳答案

尝试使用 mysqli_num_rows 代替

$user_id = $_SESSION['uid'];

$sql = "SELECT * FROM recruiting WHERE rct_app_uid = $user_id";
$result = query($sql);


if (mysqli_num_rows($result) >0){

    return true;

} else {

  redirect(ROOT_URI);

}

关于php sql值为空重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39564663/

相关文章:

php 修剪功能不起作用

php - 获取行及其之间的关系

c# - 存储过程错误 "argument 1 for routine ... is not a variable or NEW pseudo-variable in BEFORE trigger"

mysql - xtrabackup不能使用tar

php - OSX 10.10 PHP Composer 找不到所需的扩展 intl 和 mcrypt

PHP $_SESSION 变量导致 mySQL 出错

php - mysql更新语句给我一个错误

php - 为什么我使用 ipv6 从本地 php 应用程序引擎开发连接到云 sql 失败?

php - MySQL SELECT SUM 基于另一个表(另一个案例)

mysql - 无法注册新数据库