SA-MP Forums Archive
check if gang name is already taken - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: check if gang name is already taken (/showthread.php?tid=658060)



check if gang name is already taken - severance - 21.08.2018

PHP код:
stock CheckGangByName(GangName[])
{
    new 
query[100];
     
mysql_format(g_SQLquerysizeof query"SELECT * FROM `gangs` WHERE `GangName` = '%s'"GangName);
      
mysql_tquery(g_SQLquery);
    if(
cache_num_rows()) return 1;
    return 
0;

Why it doesn't work?


Re: check if gang name is already taken - GRiMMREAPER - 21.08.2018

https://sampwiki.blast.hk/wiki/MySQL/R33..._get_row_count

pawn Код:
IsGangNameTaken(gangName[]) {
    new query[100];

    mysql_format(g_SQL, query, sizeof query, "SELECT * FROM gangs WHERE GangName = '%s'", gangName);
    mysql_tquery(g_SQL, query);

    if(cache_get_row_count() > 0) {
        return 1;
    }

    return 0;
}



Re: check if gang name is already taken - severance - 21.08.2018

But I'm using MySQL r41-2

PHP код:
    if(cache_num_rows() > 0) {
        return 
1;
    } 
Tried with this, still don't detect.


Re: check if gang name is already taken - GRiMMREAPER - 21.08.2018

Print the result of the query.


Re: check if gang name is already taken - Jefff - 21.08.2018

You need use callback for tquery or Cache with old style to mysql_query

also use LIMIT 1 in query and %e instead of %s if you need mysql_format

pawn Код:
new Cache:result = mysql_query(g_SQL, query);
new rows = cache_num_rows();
cache_delete(result);
return rows;



Re: check if gang name is already taken - severance - 21.08.2018

edit: didn't saw new post


Honestly already tried your tip, but none of them works. I don't know why.

EDIT2: Works! thank you


Re: check if gang name is already taken - Rufio - 22.08.2018

Couple more tips; escape your string to avoid SQL injection. Use %e instead of %s for mysql formats

Also limit the result. Use LIMIT 1 at the end of your mysql query. You don't have to find more than 1 result.