0

I am having trouble with this code block:

 if($row['banned'] == 1) {

  header( 'Location: http://www.awsomechat.comuv.com/ban/userbanned.php' );

 } elseif ($row['banned'] == 2){
     header( 'Location: http://www.awsomechat.comuv.com/ban/userbanned.php' );

 }

Ive also tried this:

 if($row['banned'] == 1 or $row['banned']== 2) {    

 header( 'Location: http://www.awsomechat.comuv.com/ban/userbanned.php' );   
 }

But none of this works... I am trying to check if $row['banned'] equals 1 or two, and go to a specific page if the MySQL database has the value of 1 or 2 in the banned column. So, I want it to check if the column is equal to 1 or 2, then redirects to the page specified.

7
Contributors
11
Replies
12
Views
5 Years
Discussion Span
Last Post by Djmann1013
Featured Replies
  • **@Djmann1013** if($row['banned'] == '1') { } elseif ($row['banned'] == '2'){ } I think you forgot to put ''(qoutes) Read More

  • You don't ever use the word OR. Use this symbol || which means or. This symbol && means AND. if($row['banned'] == 1 or $row['banned']== 2) { } What is the message you get when you run your code? Try putting values you're trying to check within single/double qoutes. Read More

  • rotten69 didn't change your code for the OR, you cannot use OR in PHP, only in sql queries. So it should be if($row['banned'] == 1 || $row['banned'] == 2) { header ('location: url'); } You don't need speach marks around numbers/integers as suggested earlier either. Have you echo'd `$row['banned']` to … Read More

  • @rotten69 and @simplypixie 'and' and 'or' operators are both perfectly acceptable in PHP. http://php.net/manual/en/language.operators.logical.php Read More

  • I stand corrected - but, I have never once, in all my learning over the years, come across any PHP code that uses the actual words 'and' or 'or' instead of '&&' or '||' Read More

2

@Djmann1013

if($row['banned'] == '1') {

 } elseif ($row['banned'] == '2'){

 }

I think you forgot to put ''(qoutes)

2

You don't ever use the word OR. Use this symbol || which means or. This symbol && means AND.

if($row['banned'] == 1 or $row['banned']== 2) {

}

What is the message you get when you run your code? Try putting values you're trying to check within single/double qoutes.

1

rotten69 didn't change your code for the OR, you cannot use OR in PHP, only in sql queries. So it should be

if($row['banned'] == 1 || $row['banned'] == 2) {
  header ('location: url');
}

You don't need speach marks around numbers/integers as suggested earlier either.

Have you echo'd $row['banned'] to ensure you actually have a value coming from the database?

Also what happens if they aren't banned, surely you should have an else statement following your if for cases like that?

1

I stand corrected - but, I have never once, in all my learning over the years, come across any PHP code that uses the actual words 'and' or 'or' instead of '&&' or '||'

0
// Connect to server and select database.
$con = mysql_connect($host, $username, $password)or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$myusername = $_SESSION['username'];

$query = mysql_query("SELECT * FROM $tbl_name WHERE user_username='$myusername'") or die(mysql_error());
$row = mysql_fetch_array($query);

        if($row['banned'] == '1') {
         header( 'http://www.awsomechat.comuv.com/ban/userbanned.php' );
        } elseif ($row['banned'] == '2'){
         header( 'http://www.awsomechat.comuv.com/ban/userbanned.php' );
        }

It's still (ironically) not redirecting. I have it include(); in a different page, like so: include('/home/a8913488/public_html/ban/userban.php'); It takes the $_SESSION['username'] and stores it into a variable like this: $myusername = $_SESSION['username'];. I think the problem might be that it's not getting the session. But I don't know why.....It's included in the page WITH the session variable.... I just don't know..

0

I am so stupid....I put the session_start(); at the worng place on the page....Thanks for all that helped.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.