Jump to content

Why won't his code work?


soccerjunki

Recommended Posts

Hi,

 

I'm creating a chat-box application and I'm trying to add IP bans, where the php code checks if the user is banned or not and then insert the chat, but even if the IP address is banned it will still insert the chat.

 

 

$ipsql = mysql_query("SELECT * FROM bans WHERE ip='$user_ip'" or die (mysql_error()));
$bancheck = mysql_num_rows($ipsql);
if($bancheck <= 0){
$sql = mysql_query("INSERT INTO chats (user_ip, user_name, chat_body, date_time) 
        VALUES('$user_ip','$user_name','$chat_body',now())")  
        or die (mysql_error());
}

 

Thanks,

Soccerjunki

Link to comment
https://forums.phpfreaks.com/topic/261025-why-wont-his-code-work/
Share on other sites

your query line is wrong:

//$ipsql = mysql_query("SELECT * FROM bans WHERE ip='$user_ip'" or die (mysql_error()));  should be:
$ipsql = mysql_query("SELECT * FROM bans WHERE ip='$user_ip'") or die (mysql_error());

also have you checked the value in $bancheck to make sure it's what you think it should be?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.