MySQL problem
#1

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

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

Problem is resolved. It was an issue with host only accepting connections from "localhost" and trying to run it from a different server.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)