SA-MP Forums Archive
MySQL question - 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: MySQL question (/showthread.php?tid=588819)



MySQL question - Yerro - 12.09.2015

Hello,

I want to do this:

Code:
mysql_query("SELECT * FROM `players` WHERE `Name` = '%s'", inputtext);
All right, now, How can I advertise when a "Name" selected doesn't exist in the table?

Thank you.


Re: MySQL question - Kyle - 12.09.2015

Check the num rows.

Code:
mysql_query("SELECT * FROM `players` WHERE `Name` = '%s'", inputtext);
mysql_store_result();
if(!mysql_num_rows()) return SendClientMessage(playerid, -1, "User DOESN'T exist");



Respuesta: MySQL question - Zume - 12.09.2015

which version of MySQL you have?. if is the last you can do something like this:

PHP Code:
stock AccountExist(name[])
{
    new
        
str[64];
        
    
format(strsizeof str"SELECT * FROM `players` WHERE `Name` = '%s'"name);
    new
        
Cache:result mysql_query(MySQL_Connectionstr),
        
val = ((cache_num_rows() > 0) ? (true) : (false));
    
cache_delete(result);
    return 
val;

or

PHP Code:
stock AccountExist(name[])
{
    new
        
str[64];
    
format(strsizeof str"SELECT * FROM `players` WHERE `Name` = '%s'"name);
    
mysql_query(str); 
    
mysql_store_result();
    
    new
        
TRUE mysql_num_rows() > true false;
    
mysql_free_result();
    
    return 
TRUE;

PHP Code:
if(!AccountExist(inputtext))
{
    
// the account not exist




Respuesta: Re: MySQL question - Yerro - 12.09.2015

Quote:
Originally Posted by KyleSmith
View Post
Check the num rows.

Code:
mysql_query("SELECT * FROM `players` WHERE `Name` = '%s'", inputtext);
mysql_store_result();
if(!mysql_num_rows()) return SendClientMessage(playerid, -1, "User DOESN'T exist");
THANKS YOU!!


Re: Respuesta: Re: MySQL question - Kyle - 13.09.2015

Quote:
Originally Posted by Yerro
View Post
THANKS YOU!!
Oops, don't forget to add mysql_free_result(); at the end of the query, after num_rows.


Re: MySQL question - iggy1 - 13.09.2015

Also escape the string because it could contain SQL injection code. (assuming inputtext is from OnDialogResponse)