Latest MySQL version problem
#1

Hello guys! As I said in the title I'm using the latest MySQL version! When I'm trying to check if player's name exists it always create another account with the same name. Here is my code:
PHP код:
new string[256];
format(string128"SELECT * FROM `accounts` WHERE Username = '%e'"PlayerName(playerid));
mysql_tquery(zMySQLstring);
if(
cache_num_rows())
{
    
//My Register Code
}
else
{
    
//My Login Code

Reply
#2

Код:
new string[256]; 
format(string, 128, "SELECT * FROM `accounts` WHERE Username = '%e'", PlayerName(playerid)); 
mysql_tquery(zMySQL, string, "OnAccountCheck", "d", "playerid);
Код:
public OnAccountCheck(playerid)
{
if(cache_num_rows()) 
{ 
    //My Register Code 
} 
else 
{ 
    //My Login Code 
}  
}
Reply
#3

Thank you m4karow, +1 REP
Reply
#4

Read this : http://forum.sa-mp.com/showpost.php?...79&postcount=1
Plus: when you use "format", use sizeof(..) instead of putting a numeric value. It's better if you need to change the string's size at the declaration.
Reply
#5

Note that cache_num_rows() returns the amount of rows. Which means it will be 0 aka false when there is no account yet. Your if blocks should be turned around:

Код:
if(cache_num_rows()) 
{ 
    // My Login Code 
} 
else 
{ 
    // My Register Code 
}
Reply
#6

There is one thing you left out, and it was this:



the function "format" doesn't support escaping, so instead you should use the provided function "mysql_format" instead. Documentation: https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_format

Therefore, your query never finds any other accounts, because the server sends the format with the %e, and not the name you want.
Reply
#7

new string[256];
format(string, 128,

String sizes are different and I don't think you need that long of a string, you just waste memory.

44 char long is the query without the name, add to it 24 for the username, +1 for terminal = 69 long string.
new string[69];

It'd mean that you'd have 187 unused/empty cells at all times.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)