SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 02/09/2018, 07:27 PM   #1
Aerotactics
High-roller
 
Aerotactics's Avatar
 
Join Date: Jun 2013
Location: return 0;
Posts: 1,083
Reputation: 112
Default MySQL not inserting entries [RESOLVED]

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;
}

Last edited by Aerotactics; 05/09/2018 at 03:16 AM.
Aerotactics is offline   Reply With Quote
Old 02/09/2018, 08:08 PM   #2
Stormalle
Little Clucker
 
Join Date: Aug 2018
Posts: 20
Reputation: 0
Default Re: MySQL not inserting entries

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
Stormalle is offline   Reply With Quote
Old 02/09/2018, 11:35 PM   #3
Shinja
Gangsta
 
Shinja's Avatar
 
Join Date: Jan 2016
Posts: 972
Reputation: 107
Default Re: MySQL not inserting entries

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
Shinja is offline   Reply With Quote
Old 03/09/2018, 02:46 AM   #4
Aerotactics
High-roller
 
Aerotactics's Avatar
 
Join Date: Jun 2013
Location: return 0;
Posts: 1,083
Reputation: 112
Default Re: MySQL not inserting entries

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.
Aerotactics is offline   Reply With Quote
Old 03/09/2018, 02:58 AM   #5
solstice_
Gangsta
 
solstice_'s Avatar
 
Join Date: Feb 2016
Location: basement
Posts: 540
Reputation: 70
Default Re: MySQL not inserting entries

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
solstice_ is offline   Reply With Quote
Old 03/09/2018, 03:14 AM   #6
Aerotactics
High-roller
 
Aerotactics's Avatar
 
Join Date: Jun 2013
Location: return 0;
Posts: 1,083
Reputation: 112
Default Re: MySQL not inserting entries

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
Aerotactics is offline   Reply With Quote
Old 03/09/2018, 03:22 AM   #7
solstice_
Gangsta
 
solstice_'s Avatar
 
Join Date: Feb 2016
Location: basement
Posts: 540
Reputation: 70
Default Re: MySQL not inserting entries

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;

solstice_ is offline   Reply With Quote
Old 03/09/2018, 04:14 AM   #8
Aerotactics
High-roller
 
Aerotactics's Avatar
 
Join Date: Jun 2013
Location: return 0;
Posts: 1,083
Reputation: 112
Default Re: MySQL not inserting entries

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.
Aerotactics is offline   Reply With Quote
Old 03/09/2018, 05:00 AM   #9
Zeth
Huge Clucker
 
Zeth's Avatar
 
Join Date: Feb 2017
Location: Titan
Posts: 428
Reputation: 114
Default Re: MySQL not inserting entries

escape the string! Use '%e' instead of '%s'
Zeth is offline   Reply With Quote
Old 03/09/2018, 08:19 AM   #10
Calisthenics
High-roller
 
Join Date: May 2018
Posts: 1,227
Reputation: 205
Default Re: MySQL not inserting entries

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.
Calisthenics is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting with MySQL TracerX Scripting Help 2 10/07/2016 12:37 AM
inserting MySQL +rep iBots Scripting Help 2 21/04/2015 08:23 AM
MySQL not inserting zT KiNgKoNg Scripting Help 2 01/11/2013 08:45 AM
syntax for deleting multiple entries in mysql THE_KNOWN Help Archive 9 12/02/2011 09:38 AM


All times are GMT. The time now is 07:52 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.