PDA

View Full Version : MySQL not inserting entries


Aerotactics
02/09/2018, 07:27 PM
I have a valid connection to the host, but the query isn't writing entries.

EDIT: Thanks for the support to a new MySQL user. These are the right questions:

Is mysql_log enabled? The query can fail if the rest of the columns you did not specify in the query do not have a default value. Have you tried executing the query you printed for debug purposes earlier in phpMyAdmin and see the results there?

EDIT: A per-player salt is a better idea.

Short Answer: Integers require a default value.

Dialog:DIALOG_REGISTER(playerid, response, listitem, inputtext[])
{
if(!response) return Kick(playerid);
new passhash[257];
SHA256_PassHash(inputtext, #SALT, passhash, sizeof passhash);
pInfo[playerid][Password] = passhash;
new query[256];
mysql_format(gSQL, query, sizeof query, "INSERT INTO `users` (`Name`, `Password`, `IP`) VALUES ('%s', '%s', '%s')", pName[playerid], passhash, pInfo[playerid][IP]);
mysql_tquery(gSQL, query, "OnPlayerRegister", "i", playerid);
Dialog_Show(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "alone", "Please enter your password.", "Enter", "Exit");
return 1;
}

function OnPlayerRegister(playerid)
{
pInfo[playerid][SQLID] = cache_insert_id();
return 1;
}


https://puu.sh/BoBmI/25f15929a4.png

Stormalle
02/09/2018, 08:08 PM
Dialog:DIALOG_REGISTER(playerid, response, listitem, inputtext[])
{
if(!response) return Kick(playerid);
new passhash[257];
SHA256_PassHash(inputtext, #SALT, passhash, sizeof passhash);
pInfo[playerid][Password] = passhash;
new query[256];
format(query, sizeof(query), "INSERT INTO `users` (`Password`, `Name`, `IP`) VALUES ('%s', '%s', '%s')", passhash, pName[playerid], pInfo[playerid][IP]);
gSQL = mysql_tquery(gSQL, query, "OnPlayerRegister", "i", playerid);
Dialog_Show(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "alone", "Please enter your password.", "Enter", "Exit");
return 1;
}


maybe try this

Shinja
02/09/2018, 11:35 PM
Dialog:DIALOG_REGISTER(playerid, response, listitem, inputtext[])
{
if(!response) return Kick(playerid);
new passhash[257];
SHA256_PassHash(inputtext, #SALT, passhash, sizeof passhash);
pInfo[playerid][Password] = passhash;
new query[256];
format(query, sizeof(query), "INSERT INTO `users` (`Password`, `Name`, `IP`) VALUES ('%s', '%s', '%s')", passhash, pName[playerid], pInfo[playerid][IP]);
gSQL = mysql_tquery(gSQL, query, "OnPlayerRegister", "i", playerid);
Dialog_Show(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "alone", "Please enter your password.", "Enter", "Exit");
return 1;
}


maybe try this

Dafak?


1.Print the query after formating it and check (debug)
2.Does OnPlayerRegister get called? (you can check with debug)
3.Check mysql_logs for any errors

Aerotactics
03/09/2018, 02:46 AM
Dafak?


1.Print the query after formating it and check (debug)
2.Does OnPlayerRegister get called? (you can check with debug)
3.Check mysql_logs for any errors

1 and 2, you're right, I should debug.

3) I cant find the logs in PHPMyAdmin

EDIT: OnPlayerRegister is not getting called.

solstice_
03/09/2018, 02:58 AM
3) I cant find the logs in PHPMyAdmin

You can find the logs in logs/plugins/mysql_log.txt

Aerotactics
03/09/2018, 03:14 AM
You can find the logs in logs/plugins/mysql_log.txt

Found it, no errors.

EDIT:
Here's the SAMP Output: [20:10:29] INSERT INTO `users` (`Name`, `Password`, `IP`) VALUES ('Aero', 'SNIP', '127.0.0.1')

And here's the latest MySQL entry: 2018-08-05T05:27:01.398735Z 0 [Warning] InnoDB: New log files created, LSN=2551175

solstice_
03/09/2018, 03:22 AM
Have you tried debugging them?

EDIT: Try to debug them, here's an example:

function OnPlayerRegister(playerid)
{
pInfo[playerid][SQLID] = cache_insert_id();
print("OnPlayerRegister has been called");
return 1;
}

Aerotactics
03/09/2018, 04:14 AM
Have you tried debugging them?

EDIT: Try to debug them, here's an example:

function OnPlayerRegister(playerid)
{
pInfo[playerid][SQLID] = cache_insert_id();
print("OnPlayerRegister has been called");
return 1;
}

Yes, and the callback was not called. I even put in a static query to test if it would callback then and it didn't.

Zeth
03/09/2018, 05:00 AM
escape the string! Use '%e' instead of '%s'

Calisthenics
03/09/2018, 08:19 AM
Is mysql_log enabled? The query can fail if the rest of the columns you did not specify in the query do not have a default value. Have you tried executing the query you printed for debug purposes earlier in phpMyAdmin and see the results there?

EDIT: A per-player salt is a better idea.

Shinja
03/09/2018, 01:01 PM
Escape the strings, golden rule
mysql_format(gSQL, query, sizeof query, "INSERT INTO `users` (`Name`, `Password`, `IP`) VALUES ('%e', '%e', '%e')", pName[playerid], passhash, pInfo[playerid][IP]);


If it doesnt work yet, try again with mysql_log(ALL)