SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 12/09/2015, 07:33 PM   #1
Yerro
Little Clucker
 
Join Date: Oct 2013
Location: Spain
Posts: 35
Reputation: 3
Default MySQL question

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.
__________________
Whetstone RP || http://www.whetstone.es/ || ES
Yerro is offline   Reply With Quote
Old 12/09/2015, 07:39 PM   #2
Kyle
High-roller
 
Join Date: Mar 2009
Location: United Kingdom
Posts: 2,262
Reputation: 347
Default Re: MySQL question

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");
Kyle is offline   Reply With Quote
Old 12/09/2015, 07:46 PM   #3
Zume
High-roller
 
Zume's Avatar
 
Join Date: Nov 2011
Location: El Salvador
Posts: 1,642
Reputation: 311
Default Respuesta: MySQL question

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

__________________
Zume is offline   Reply With Quote
Old 12/09/2015, 08:13 PM   #4
Yerro
Little Clucker
 
Join Date: Oct 2013
Location: Spain
Posts: 35
Reputation: 3
Default Respuesta: Re: MySQL question

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!!
__________________
Whetstone RP || http://www.whetstone.es/ || ES
Yerro is offline   Reply With Quote
Old 13/09/2015, 10:38 AM   #5
Kyle
High-roller
 
Join Date: Mar 2009
Location: United Kingdom
Posts: 2,262
Reputation: 347
Default Re: Respuesta: Re: MySQL question

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.
Kyle is offline   Reply With Quote
Old 13/09/2015, 10:58 AM   #6
iggy1
High-roller
 
iggy1's Avatar
 
Join Date: Mar 2009
Location: One past the end.
Posts: 2,421
Reputation: 273
Default Re: MySQL question

Also escape the string because it could contain SQL injection code. (assuming inputtext is from OnDialogResponse)
iggy1 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL question PaulDinam Scripting Help 3 18/03/2013 10:03 PM
MySQL Question CONTROLA Scripting Help 0 29/08/2012 02:43 PM
MySQL Question PRototype-RP Server Support 5 01/12/2011 04:34 PM
Mysql Move a record? (Mysql/pawn Question) DarrenReeder Help Archive 4 05/11/2010 07:23 PM
an question about mySQL WardenCS Help Archive 2 19/03/2010 01:38 PM


All times are GMT. The time now is 01:35 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.