check if gang name is already taken
#1

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?
Reply
#2

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;
}
Reply
#3

But I'm using MySQL r41-2

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

Print the result of the query.
Reply
#5

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;
Reply
#6

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
Reply
#7

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)