MySQL AND operator
#1

I inserted a row to my user database, in order to test my IP banning system
That's the pawn code
PHP Code:
    new query[248];
    
mysql_format(mysqlquerysizeof(query), "SELECT `BannedBy`, `BanReason`, `BannedDate`, `Username` WHERE `IP`='%e' AND `Banned`='1'"RPIP(playerid));
    
mysql_tquery(mysqlquery"CheckBan""i"playerid); 
PHP Code:
forward CheckBan(playerid);
public 
CheckBan(playerid)
{
    new 
rowsfields;
    
cache_get_data(rowsfieldsmysql);
    if(
rows)
    {
        new 
banreason[128], bannedby[24], bandate[10], username[24], string[128];
        
cache_get_field_content(0"BannedBy"bannedbymysqlsizeof(bannedby));
        
cache_get_field_content(0"BanReason"banreasonmysqlsizeof(banreason));
        
cache_get_field_content(0"BannedDate"bandatemysqlsizeof(bandate));
        
cache_get_field_content(0"Username"usernamemysqlsizeof(username));
        
SendClientMessage(playeridCOLOR_GREEN"-------[Banned]-------");
        
format(stringsizeof(string), "Username: %s || Banning Date: %s"usernamebandate);
        
SendClientMessage(playeridCOLOR_REDstring);
        
format(stringsizeof(string), "IP Address: %s || Banned By: %s"RPIP(playerid), bannedby);
        
SendClientMessage(playeridCOLOR_REDstring);
        
format(stringsizeof(string), "Reason: %s"banreason);
        
SendClientMessage(playeridCOLOR_REDstring);
        
SendClientMessage(playeridCOLOR_YELLOW"If you think that you have been wrongfully banned, visit our forums and apply for an unban.");
        
SendClientMessage(playeridCOLOR_GREEN"-------[Banned]-------");
        
SetTimerEx("DelayedKick"10000"i"playerid);
    }

That's the error:
Code:
[01:35:09] [ERROR] CMySQLQuery::Execute[CheckBan] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE `IP`='127.0.0.1' AND `Banned`='1'' at line 1
Reply
#2

PHP Code:
mysql_format(mysqlquerysizeof(query), "SELECT `BannedBy`, `BanReason`, `BannedDate`, `Username` FROM table_ban WHERE `IP`='%e' AND `Banned`='1'"RPIP(playerid)); 
you forget the table name
Reply
#3

Quote:
Originally Posted by WhiteKinG
View Post
PHP Code:
mysql_format(mysqlquerysizeof(query), "SELECT `BannedBy`, `BanReason`, `BannedDate`, `Username` FROM table_ban WHERE `IP`='%e' AND `Banned`='1'"RPIP(playerid)); 
you forget the table name
Thanks
Reply
#4

You also don't need to wrap integer values with quotations:

Code:
`Banned`='1'
// Becomes
`Banned`=1
Reply
#5

Quote:
Originally Posted by Isolated
View Post
You also don't need to wrap integer values with quotations:

Code:
`Banned`='1'
// Becomes
`Banned`=1
Thanks, still doesn't work tho, no errors
PHP Code:
    mysql_format(mysqlquerysizeof(query), "SELECT `BannedBy`, `BanReason`, `BannedDate`, `Username` FROM `Users` WHERE `IP`='%e' AND `Banned`=1"RPIP(playerid));
    
mysql_tquery(mysqlquery"CheckBan""i"playerid); 
PHP Code:
forward CheckBan(playerid);
public 
CheckBan(playerid)
{
    new 
rowsfields;
    
cache_get_data(rowsfieldsmysql);
    if(
rows)
    {
        new 
banreason[128], bannedby[24], bandate[10], username[24], string[128];
        
cache_get_field_content(0"BannedBy"bannedbymysqlsizeof(bannedby));
        
cache_get_field_content(0"BanReason"banreasonmysqlsizeof(banreason));
        
cache_get_field_content(0"BannedDate"bandatemysqlsizeof(bandate));
        
cache_get_field_content(0"Username"usernamemysqlsizeof(username));
        
SendClientMessage(playeridCOLOR_GREEN"-------[Banned]-------");
        
format(stringsizeof(string), "Username: %s || Banning Date: %s"usernamebandate);
        
SendClientMessage(playeridCOLOR_REDstring);
        
format(stringsizeof(string), "IP Address: %s || Banned By: %s"RPIP(playerid), bannedby);
        
SendClientMessage(playeridCOLOR_REDstring);
        
format(stringsizeof(string), "Reason: %s"banreason);
        
SendClientMessage(playeridCOLOR_REDstring);
        
SendClientMessage(playeridCOLOR_YELLOW"If you think that you have been wrongfully banned, visit our forums and apply for an unban.");
        
SendClientMessage(playeridCOLOR_GREEN"-------[Banned]-------");
        
SetTimerEx("DelayedKick"10000"i"playerid);
    }

Code:
[02:47:54] [DEBUG] mysql_format - connection: 1, len: 248, format: "SELECT `BannedBy`, `BanReason`, `BannedDate`, `Username` FROM `Users` WHERE `IP`='%e' AND `Banned`=1"
[02:47:54] [DEBUG] mysql_tquery - connection: 1, query: "SELECT `BannedBy`, `BanReason`, `BannedDate`, `Username` FROM `U", callback: "CheckBan", format: "i"
[02:47:54] [DEBUG] CMySQLQuery::Execute[CheckBan] - starting query execution
[02:47:54] [DEBUG] CMySQLQuery::Execute[CheckBan] - query was successfully executed within 0.311 milliseconds
[02:47:54] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[02:47:54] [DEBUG] Calling callback "CheckBan"..
[02:47:54] [DEBUG] cache_get_data - connection: 1
[02:47:54] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
Reply
#6

Can you throw in a print(query)? I'm wondering whether mysql_format isn't actually formatting it properly - your query is executing successfully, which suggests the IP might be being fucked? I had a couple of issues a year or two back with mysql_format glitching out and not replacing %e because of something weird like array sizes.
Reply
#7

Quote:
Originally Posted by Alcatrik
View Post
Can you throw in a print(query)? I'm wondering whether mysql_format isn't actually formatting it properly - your query is executing successfully, which suggests the IP might be being fucked? I had a couple of issues a year or two back with mysql_format glitching out and not replacing %e because of something weird like array sizes.
There you go
Code:
SELECT `BannedBy`, `BanReason`, `BannedDate`, `Username` FROM `Users` WHERE `IP`='127.0.0.1' AND `Banned`=1
Reply
#8

How about you select Banned value as well? And check if its 1 then send banned message otherwise ignre
Reply
#9

Quote:
Originally Posted by iLearner
View Post
How about you select Banned value as well? And check if its 1 then send banned message otherwise ignre
The whole point is to check if the player is banned before I select everything, but I will try it.
Reply
#10

Quote:
Originally Posted by iLearner
View Post
How about you select Banned value as well? And check if its 1 then send banned message otherwise ignre
Dumb me, I forgot to change "Banned" value to 1 for testing XD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)