MySQL not inserting entries
#1

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:

Quote:
Originally Posted by Calisthenics
View Post
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.

Code:
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;
}
Reply
#2

HTML Code:
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
Reply
#3

Quote:
Originally Posted by Stormalle
View Post
HTML Code:
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
Reply
#4

Quote:
Originally Posted by Shinja
View Post
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.
Reply
#5

Quote:
Originally Posted by Aerotactics
View Post
3) I cant find the logs in PHPMyAdmin
You can find the logs in logs/plugins/mysql_log.txt
Reply
#6

Quote:
Originally Posted by willbedie
View Post
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
Reply
#7

Have you tried debugging them?

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

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

Reply
#8

Quote:
Originally Posted by willbedie
View Post
Have you tried debugging them?

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

PHP Code:
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.
Reply
#9

escape the string! Use '%e' instead of '%s'
Reply
#10

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

Escape the strings, golden rule
PHP код:
mysql_format(gSQLquerysizeof query"INSERT INTO `users` (`Name`, `Password`, `IP`) VALUES ('%e', '%e', '%e')"pName[playerid], passhashpInfo[playerid][IP]); 
If it doesnt work yet, try again with mysql_log(ALL)
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)