-1

I am attempted to check the database for a varchar "race" and if it's null redirect to a page. this is my code, ive made sure that the var is null yet it does nothing even upon reloading how do i make php redirect

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

2 Answers2

1

you are not fetching any records so maybe use mysql_fetch_assoc first?

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

P.S. get rid of MySQL_.* functions use PDO or MySQLi

GGio
  • 7,563
  • 11
  • 44
  • 81
  • In some rare case not doing the `exit;` after a php redirect would close the browser. Yep... I already saw this. Many times. – poudigne Mar 26 '13 at 18:26
0

Did you executed the header statement before anything was loaded on the page (html code or a echo), sinse you cannot use header() if you already made somthing in the body of the response

so:

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

will not work but:

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

will

Edo Post
  • 727
  • 7
  • 18