0

Hi. I am having trouble with this script:

<?php
$host="mysql.host.com"; // Host name 
$username="username"; // Mysql username 
$password="password"; // Mysql password 
$db_name="DB_NAME"; // Database name 
$tbl_name="table"; // Table name



$myusername = $_SESSION['myusername']; // Session on login page, in a variable.

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

// Select everything that we need.
$sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and banned='1'"; // Possible problem...I think....
$query = mysql_query($sql);



$row = mysql_fetch_array($query);

if($banned == 1) { // If the person on the table has the "1" value in banned, ban them..

header('Location: http://www.mywebsite.com/banned/banneduser.php'); // Ban page

} else {

// Their not banned... Let them in ..... Don't do anything...

}
?>

This code works, it's just not working properly. This code is supposed to redirect the user with the "1" value in the column "banned". Basicly, this script is supposed to "crawl" on the table and search for the user in the table with the "1" value in "banned", while the user is online, and redirect them to the "banned" page if the "banned" value is "1". The script currently does not redirect how I want it to. Instead, it lets the people that are banned online. I don't know why. I tried jumping through all the hoops, and never got it working. I would be glad if someone fixed it.

5
Contributors
7
Replies
9
Views
5 Years
Discussion Span
Last Post by diafol
0

Change this:

$query = mysql_query($sql);

with:

$query = mysql_query($sql) or die(mysql_error());

and check what you get. Also the session of the banned user should be destroyed.

0

Now it's only going to the ban page. No matter if the user is banned or not. I tried adding:

$query = mysql_query($sql) or die(mysql_error());

and fixing the if line to:

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

header('Location: http://www.aphpsite.comuv.com/ban/banpage.php');

} else {

// Let them in .....

}

All the MySQL errors are gone, it's just redirecting to the ban page no matter if your banned. It's like it skips the else statement.

0

Got it working. It was the else statement. I had to take it out. Thanks for your guys help.

0

Dunno if it's still relevant, but I always put an exit; after any header redirect.

0

I know it's really pathetic, but I just had a dream about that. I had to sift through all my code putting an exit(); after all my header redirects. I haven't done it for real, but that was last night's nightmare, I kid you not. I need to get out more.

0

Whoah nightmare - wide-eyed and preg-less. Could it be a message from the subconscious, telling you to find the exit so that you CAN go out more? Try it - I did on Friday night. Still suffering - from cringing - I told all my mates I loved them. Come to think of it Dani, I think I told you I loved you too. :)

Freedom may be over-rated after all...

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.