PDA

View Full Version : Mysql errors


DerickClark
17/10/2015, 02:04 PM
[07:00:26] [DEBUG] mysql_format - connection: 1, len: 540, format: "INSERT INTO `Players` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`)"
[07:00:26] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO `Players` (`Username`, `Password`, `IP`, `Admin`, `V", callback: "(null)", format: "(null)"
[07:00:26] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[07:00:26] [ERROR] CMySQLQuery::Execute[] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
[07:00:26] [DEBUG] CMySQLQuery::Execute[] - error will be triggered in OnQueryError
GetPlayerName(playerid, MysqlName[playerid], 24); //Getting player's name
GetPlayerIp(playerid, IP[playerid], 16); //Getting layer's IP
mysql_format(mysql, query, sizeof(query),"SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1", MysqlName[playerid]);

case 2: //register dialog
{
if(!response) return Kick(playerid); //if they clicked Quit, we will kick them
if(strlen(inputtext) < 6) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Register", "In order to play, you need to register.\nYour password must be at least 6 characters long!", "Register", "Quit");
//strlen checks a lenght of a string. so if player types their password that is lower than 6, we tell them; Your password must be at least 6 characters long!
WP_Hash(PlayerInfo[playerid][Password], 129, inputtext); //hashing inputtext
mysql_format(mysql, query, sizeof(query), "INSERT INTO `Players` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`)", MysqlName[playerid], PlayerInfo[playerid][Password], IP[playerid]);
//Now let's create a new row and insert player's information in it
mysql_tquery(mysql, query, "", "");
//let's execute the query
}
And it's not writing the player account into the database.

karemmahmed22
17/10/2015, 02:15 PM
first this should be

mysql_format(mysql, query, sizeof(query),"SELECT * FROM players WHERE `Username` = '%e' LIMIT 1;", MysqlName[playerid]);

second:

mysql_format(mysql, query, sizeof(query), "INSERT INTO Players (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`) VALUES ('%s', '%s', '%s', '0', '0', '0');", MysqlName[playerid], PlayerInfo[playerid][Password], IP[playerid]);

Not sure if I should use %s or %e in formats, try both..
Hope this work (I didn't test it, But corrected your mysql query)
I don't have any knowledge about MySQL with SAMP
But I used to make login / register system for big projects in programming languages like vb.net / c#
I corrected your query, It should work now

iggy1
17/10/2015, 02:16 PM
Not used MYSQL plugin in a long time but...

mysql_format(mysql, query, sizeof(query), "INSERT INTO `Players` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`)", MysqlName[playerid], PlayerInfo[playerid][Password], IP[playerid]);

Looks to me like you should have some format specifiers (%s, %i etc) there.

Too slow.

DerickClark
17/10/2015, 02:25 PM
Thanks everyone, i'm just new to Mysql.
and i got 1 more error on OnPlayerDisconnect


new query[540]; //query[128] is for formatting our query and Float:pos[3] is for getting and saving player's position
mysql_format(mysql, query, sizeof(query), "UPDATE `Players` SET ,`MysqlID`='0'",\
PlayerInfo[playerid][MysqlID]);

[07:32:26] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `Players` SET ,`MysqlID`='0'", callback: "(null)", format: "(null)"
[07:32:26] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[07:32:26] [ERROR] CMySQLQuery::Execute[] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`MysqlID`='0'' at line 1
[07:32:26] [DEBUG] CMySQLQuery::Execute[] - error will be triggered in OnQueryError

karemmahmed22
17/10/2015, 02:33 PM
mysql_format(mysql, query, sizeof(query), "UPDATE Players SET `MysqlID`='%i';",PlayerInfo[playerid][MysqlID]);

EDIT:
I don't understand what is this 'mysqlid'
But this query above will update the whole table's column (mysqlid) to PlayerInfo[playerid][MysqlID]
Are you sure you want that?
If you don't, Use WHERE clause in your mysql query ex:


UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value

DerickClark
17/10/2015, 03:00 PM
mysql_format(mysql, query, sizeof(query), "UPDATE Players SET `MysqlID`='%i';",PlayerInfo[playerid][MysqlID]);

EDIT:
I don't understand what is this 'mysqlid'
But this query above will update the whole table's column (mysqlid) to PlayerInfo[playerid][MysqlID]
Are you sure you want that?
If you don't, Use WHERE clause in your mysql query ex:


UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value


I think its a account id