-1

我试图检查数据库中是否存在 varchar “race”,如果它为空,则重定向到页面。这是我的代码,我确保 var 为空,但即使在重新加载时它什么也不做我如何进行 php 重定向

    <?php
    $check_bone_query = mysql_query("SELECT bone FROM users WHERE name = '".$user->name."'");
    {
    if($check_bone_query == NULL){
    header('Location: /bone');
    }  
`   }  
    ?>
4

2 回答 2

1

您没有获取任何记录,所以可能mysql_fetch_assoc先使用?

$row = mysql_fetch_assoc($check_bone_query);
if (is_null($row)) { //or use empty()
  header('Location: /bone'); exit;
}

PS摆脱MySQL_.*函数使用PDOMySQLi

于 2013-03-26T18:04:03.230 回答
0

您是否在页面上加载任何内容(html 代码或回显)之前执行了 header 语句,如果您已经在响应的正文中进行了某些操作,则无法使用 header()

所以:

<html>
 some html
</html>
<?php header(location: 'your new location'); ?>

不会工作,但是:

 <?php header(location: 'your new location'); ?>
 <html>
  some html
 </html>

将要

于 2013-03-26T18:05:22.600 回答