MySQL problem - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: MySQL problem (
/showthread.php?tid=235091)
MySQL problem -
randomkid88 - 05.03.2011
So I'm experimenting with MySQL and I am trying to replace my existing reg/login system with MySQL. I just started and tried making the check to see if the account exists, but keep having mysql_num_rows returning -1. Here is the check so far:
pawn Код:
new Query[128], escName[24];
mysql_real_escape_string(Name, escName);
format(Query, sizeof(Query), "SELECT * FROM `pinfo` WHERE name = '%s'", escName);
mysql_query(Query);
mysql_store_result();
printf("%d", mysql_num_rows());
if(mysql_num_rows() == 0)
{
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Welcome to The Community!", "Please enter a password below to register with our server!", "Register", "Cancel");
}
else
{
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Welcome Back!", "Please enter your password to login!", "Login", "Cancel");
}
mysql_free_result();
I manually inserted the row into the table so I know it exists. Like I said, on the print of mysql_num_rows I keep getting -1. Any help is appreciated. This is G-stylezzz plugin, R5 for windows by the way.
EDIT: I did some debugging of the query and name is ' ', so the problem appears to be there. escName is always blank.
Re: MySQL problem - [L3th4l] - 05.03.2011
Are you storing the player's name in the "Name" variable??
Try using this quick function that I've just made:
pawn Код:
LoadPlayer(playerid)
{
new
Query[MAX_PLAYER_NAME + 70],
EscName[MAX_PLAYER_NAME];
mysql_real_escape_string(pName(playerid), EscName);
format(Query, sizeof(Query), "SELECT * FROM `pinfo` WHERE `name` = '%s'", EscName);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() > 0)
{
// Account Exists
}
else
{
// Account Does NOT Exists
}
mysql_free_result();
}
Re: MySQL problem -
randomkid88 - 05.03.2011
Problem is resolved. It was an issue with host only accepting connections from "localhost" and trying to run it from a different server.