AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Error first time SQL (https://forums.alliedmods.net/showthread.php?t=215338)

ironskillz1 05-06-2013 13:43

Error first time SQL
 
This is my first time trying to understand MySQL

Im getting this error in the console and
it doesnt save or load.

Error:
Code:

[pointmod.amxx] Load Query failed. [1] near "AUTO_INCREMENT": syntax error
Code:
Code:

public plugin_precache()
{
 MySQL_Tuple = SQL_MakeDbTuple(Host, User, Pass, Db)
 SQL_ThreadQuery(MySQL_Tuple, "SQL_TrashHandler", "CREATE TABLE IF NOT EXISTS `Points_Shop`(`id` INT(1) NOT NULL AUTO_INCREMENT, `steamid` VARCHAR(32), `name` VARCHAR(32), `points` INT(1), `kills` INT(1), `killed` INT(1), `suicides` INT(1), `survives` INT(1), PRIMARY KEY(`id`))")
}
public client_putinserver(id)
{
 MySQL_Load(id)
}
public client_disconnect(id)
{
 MySQL_Save(id)
}
public MySQL_Save(const id) {
 new szBugName[32], szName[32];
 get_user_name(id, szBugName, charsmax(szBugName))
 MakeStringSQLSafe(szBugName, szName, charsmax(szName))
 
 new szAuthid[32]
 get_user_authid(id, szAuthid, charsmax(szAuthid))
 for( new i ; i < MAX_SKINS ; i ++ )
 
 formatex(MySQL_Query, charsmax(MySQL_Query), "UPDATE `Points_Shop` SET `name` = '%s', `points` = '%i', `totalpoints` = '%i', `jumps` = '%i', `knife` = '%d', `player` = '%d', `bought` = '%i' WHERE `steamid`='%s'", szName, gKillerPoints[id], gTotalKillerPoints[id], vJump[id], knife_model[id], player_model[id], g_bBoughtSkin[id][i], szAuthid)
 SQL_ThreadQuery(MySQL_Tuple, "SQL_TrashHandler", MySQL_Query)
}
MakeStringSQLSafe(const input[], output[], len)
{
 copy(output, len, input);
 replace_all(output, len, "'", "*");
 replace_all(output, len, "^"", "*");
 replace_all(output, len, "`", "*");
}
public MySQL_Load(id) {
 new szAuthid[32]
 get_user_authid(id, szAuthid, charsmax(szAuthid))
 
 new Temp[1]
 Temp[0] = id
 
 formatex(MySQL_Query, charsmax(MySQL_Query), "SELECT * FROM `Points_Shop` WHERE `steamid` = '%s'", szAuthid)
 SQL_ThreadQuery(MySQL_Tuple, "Load_PlayerInfo", MySQL_Query, Temp, sizeof(Temp))
}
public Load_PlayerInfo(FailState, Handle:Query, Error[], Errcode, Data[], DataSize) {
 if(FailState == TQUERY_CONNECT_FAILED)
  log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
 else if(FailState == TQUERY_QUERY_FAILED)
  log_amx("Load Query failed. [%d] %s", Errcode, Error)
 
 new id = Data[0]
 
 new szName[32], szBugName[32], szAuthid[32];
 get_user_name(id, szBugName, charsmax(szBugName));
 MakeStringSQLSafe(szBugName, szName, sizeof(szName) - 1);
 
 get_user_authid(id, szAuthid, charsmax(szAuthid))
 
 formatex(MySQL_Query, charsmax(MySQL_Query), "INSERT INTO `Points_Shop` (`steamid`, `name`) VALUES ('%s', '%s')", szAuthid, szName)
 SQL_ThreadQuery(MySQL_Tuple, "SQL_TrashHandler", MySQL_Query)
}
public SQL_TrashHandler(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {
 if(FailState == TQUERY_CONNECT_FAILED)
  log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
 else if(FailState == TQUERY_QUERY_FAILED)
  log_amx("Load Query failed. [%d] %s", Errcode, Error)
 
 SQL_FreeHandle(Query)
}


YamiKaitou 05-06-2013 13:52

Re: Error first time SQL
 
Does the SQL line work when you use PHPMyAdmin or mysqladmin?

ironskillz1 05-06-2013 14:47

Re: Error first time SQL
 
Quote:

Originally Posted by YamiKaitou (Post 1947052)
Does the SQL line work when you use PHPMyAdmin or mysqladmin?

Now i got this error
Code:

[pointmod.amxx] Load Query failed. [1] no such table: Points_Shop

YamiKaitou 05-06-2013 14:59

Re: Error first time SQL
 
Does the table exist in the SQL Database?

ironskillz1 05-06-2013 15:09

Re: Error first time SQL
 
Quote:

Originally Posted by YamiKaitou (Post 1947085)
Does the table exist in the SQL Database?


i got this error when is saved with
module sqlite.
Code:

[pointmod.amxx] Load Query failed. [1] no such table: Points_Shop

YamiKaitou 05-06-2013 15:13

Re: Error first time SQL
 
Did you create the table?

ironskillz1 05-06-2013 15:15

Re: Error first time SQL
 
Quote:

Originally Posted by YamiKaitou (Post 1947097)
Did you create the table?

How can i create a table on module sqlite?

YamiKaitou 05-06-2013 15:41

Re: Error first time SQL
 
If you do not know how to create queries to SQLite, please Google them as they are slightly different from MySQL

ironskillz1 05-07-2013 13:44

Re: Error first time SQL
 
But it created new data evry time someone joins
it doesnt load the old data.
First i connect then my buddy connect
then i changed map and it created 2 new for us insted of loading !
How can i fix that!

http://i.imgur.com/tlhxu1e.png

YamiKaitou 05-07-2013 14:32

Re: Error first time SQL
 
Then you need to check if an entry exists before using INSERT


All times are GMT -4. The time now is 10:47.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.