Does not register user on INSERT INTO
#1

I'm currently busy with making an All In One script, including house/vehicle ownership systems, adminsystems, register/login

But on register, it does not insert the data in the table.

pawn Код:
stock Register(playerid, passwordstring[])
{
    new query[400], pname[24];
    GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
    //(Name, Password, AdminLevel,Score)
    format(query, sizeof(query), "INSERT INTO users (Name, Password, AdminLevel,Score) VALUES ('%s','%s',0, 0)", pname, passwordstring);
    mysql_query(query);
    Login(playerid);
    return 1;
}
What did I missed?
Reply
#2

Any?
Reply
#3

If mysql doesn't insert data, it means that the query has error in it.

Try change this:
Код:
    format(query, sizeof(query), "INSERT INTO users (Name, Password, AdminLevel,Score) VALUES ('%s','%s',0, 0)", pname, passwordstring);
to this:

Код:
    format(query, sizeof(query), "INSERT INTO users (Name, Password, AdminLevel,Score) VALUES ('%s','%s','0', '0')", pname, passwordstring);
Reply
#4

I dont know MYSQL completely but i know SQLite and whenever i need to send a query. After formatting the query i use something like this.
pawn Код:
db_free_result(db_query(database,query));
Isnt there a function like that in MYSQL? Try looking for something like that. I wish that helps.

EDIT: For inputting the strings in a query we use sqlite_escape_string. Isnt there anything like that in MYSQL?
Reply
#5

Yes we have mysql_free_result.

But I found out in the logs, using mysql_debug();
The query isn't even activated. So there must be another problem..

register dialog.
pawn Код:
if(dialogid == 2)
        {
            if(!response)
            {
                SendClientMessage(playerid, 0xFFFFFFFF, "You MUST register to play here. Please register.");
                ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD, "Register","Please enter your desired password below","Register", "Cancel");
            }
            else
            if(strlen(inputtext)>0)
            {
                new FinalPassword[132];
                WP_Hash(FinalPassword, sizeof(FinalPassword), inputtext);
                Register(playerid, FinalPassword);
                SendClientMessage(playerid, 0xFFFFFFFF, "Succesfully created the account!");
            }
        }
And the register funtion.

pawn Код:
// Registers the player
stock Register(playerid, passwordstring[])
{
    new query[500], pname[24];
    GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
    //(Name, Password, AdminLevel,Score)
    //format(query, sizeof(query), "INSERT INTO users (Name, Password, AdminLevel,Score) VALUES ('%s','%s',0, 0)", pname, passwordstring);
    format(query, sizeof(query), "INSERT INTO users (Name, Password, AdminLevel,Score) VALUES ('%s','%s','0', '0')", pname, passwordstring);
    mysql_query(query);
    Login(playerid);
    return 1;
}
Reply
#6

EDIT: ignore this, i failed!
Reply
#7

When creating a query with insert into you dont have to store it. Since it's directly going into the database, bnut that isn't in this case.
Reply
#8

Yea sorry, I always confused between SELECT and INSERT. Btw try this
pawn Код:
format(query, sizeof(query), "INSERT INTO `users` (`Name`, `Password`, `AdminLevel`,`Score`) VALUES ('%s','%s',0, 0)", pname, passwordstring);
Reply
#9

It doesn't do the query, here is the last few lines of the log:

Код:
[09:31:42] CMySQLHandler::FreeResult() - Result was successfully free'd.

[09:31:42] >> mysql_query( Connection handle: 1 )

[09:31:42] CMySQLHandler::Query(SELECT UserID FROM `users` WHERE Name = 'Kevinnn' LIMIT 1) - Successfully executed.

[09:31:42] >> mysql_store_result( Connection handle: 1 )

[09:31:42] CMySQLHandler::StoreResult() - Result was stored.

[09:31:42] >> mysql_num_rows( Connection handle: 1 )

[09:31:42] CMySQLHandler::NumRows() - Returned 0 row(s)

[09:31:42] >> mysql_free_result( Connection handle: 1 )

[09:31:42] CMySQLHandler::FreeResult() - Result was successfully free'd.
As you can see that's from the login code it call the Register function, and in the register function it call the login function, and that works. BUt it doesn't execute the query, I've no idea why.
Reply
#10

Add debug lines EVERYWHERE. I cannot stretch this enough. They will give you a visible representation of what executes and what doesn't. I should go write a tutorial on debugging as no one apparently knows how to do this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)