Garage Creation: VIA mysql error
#1

Hey guys. I'm trying to create a function to create a garage. However I keep getting the same error and I'm probably being super blonde but I can't find the bloody error.

The error I'm getting is
Код:
(error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '` = 0, `GarageOwner` = '-', `GaragePosX` = 248.198, `GaragePosY` = -1361.403, `G' at line 1
Here is my mysql code
Код HTML:
	new query[2024];
	mysql_format(g_iHandle, query, sizeof(query), "INSERT INTO `garages` SET hID` = %d, `GarageOwner` = '%s', `GaragePosX` = %f, `GaragePosY` = %f, `GaragePosZ` = %f, `GaragePosA` = %f, `GarageIntX` = %f,`GarageIntY` = %f, `GarageIntZ` = %f, `GarageIntA` = %f, `VirtualWorld` = %d, `Interior` = %d, `Status` = %d, `ForSale` = %d, `Price` = %d WHERE `gID`=%d",
		GarageInfo[id][hID],
		GarageInfo[id][GarageOwner],
		GarageInfo[id][ExtX],
		GarageInfo[id][ExtY],
		GarageInfo[id][ExtZ],
		GarageInfo[id][ExtA],
		GarageInfo[id][IntX],
		GarageInfo[id][IntY],
		GarageInfo[id][IntZ],
		GarageInfo[id][IntA],
		GarageInfo[id][vWorld],
		GarageInfo[id][IntID],
		GarageInfo[id][Status],
		GarageInfo[id][ForSale],
		GarageInfo[id][Price],
		id); 
	mysql_tquery(g_iHandle, query, "OnGarageCreated", "i", id);
Would really appreciate anyone who puts time into replying and trying to help me out.
Reply
#2

Wrong statement.

it should be 'INSERT INTO table_name (fields, ...) VALUES(field_values, ...)'
Reply
#3

Along with that above fix mentioned by @Logic_ , You are missing ` at hID.

PHP код:
mysql_format(g_iHandlequerysizeof(query), "INSERT INTO `garages` SET `hID` = %d, `GarageOwner` = '%s', `GaragePosX` = %f, `GaragePosY` = %f, `GaragePosZ` = %f, `GaragePosA` = %f, `GarageIntX` = %f,`GarageIntY` = %f, `GarageIntZ` = %f, `GarageIntA` = %f, `VirtualWorld` = %d, `Interior` = %d, `Status` = %d, `ForSale` = %d, `Price` = %d WHERE `gID`=%d",
        
GarageInfo[id][hID], 
Its not necessary to use `, you can simply avoid it.
Reply
#4

Quote:
Originally Posted by Logic_
Посмотреть сообщение
Wrong statement.

it should be 'INSERT INTO table_name (fields, ...) VALUES(field_values, ...)'
Thanks for your help. I tried that earlier however I got

Код:
(error #1054) Unknown column '%d' in 'field list'
With this code

Код:
	mysql_tquery(g_iHandle, "INSERT INTO `garages` (`gID`) VALUES(`%d`)", "OnGarageCreated", "d", id);
Reply
#5

well you are not passing any value for %d.

PHP код:
mysql_format(g_iHandlequerysizeof query"INSERT INTO `garages` (`gID`) VALUES(%d)"id);
mysql_tquery(g_iHandlequery"OnGarageCreated""d"id); 
Reply
#6

Quote:
Originally Posted by Debjit
Посмотреть сообщение
well you are not passing any value for %d.

PHP код:
mysql_format(g_iHandlequerysizeof query"INSERT INTO `garages` (`gID`) VALUES(%d)"id);
mysql_tquery(g_iHandlequery"OnGarageCreated""d"id); 
Haha thanks. Sorry I haven't scripted in a while and forgetting all the silly stuff. Now it creates a row in the database, but it's not saving anything to it. I'm getting this?

Код:
(error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''’$' at line 1
Reply
#7

You are not inserting any other value except gID and I dont know if you are doing it in OnGarageCreated.
You can try making a column unique and then getting the unique increment id using cache_insert_id(); and then saving it again in OnGarageCreated.
Reply
#8

This is what I'm doing.

Код:
mysql_tquery(g_iHandle,  "INSERT INTO `garages` (`ForSale`) VALUES(1)", "OnGarageCreated", "d", id);
Код:
public OnGarageCreated(gID)
{
	GarageInfo[gID][GID] = cache_insert_id(g_iHandle);
	Garage_Save(gID);
	return 1;
}
Код:
Garage_Save(gID)
{
	static
		query[2048];
	format(query,sizeof(query), "UPDATE `garages` SET `hID` = %d, `GarageOwner` = '%s', `GaragePosX` = %f, `GaragePosY` = %f, `GaragePosZ` = %f, `GaragePosA` = %f, `GarageIntX` = %f,`GarageIntY` = %f, `GarageIntZ` = %f, `GarageIntA` = %f, `VirtualWorld` = %d, `Interior` = %d, `Status` = %d, `ForSale` = %d, `Price` = %d WHERE `gID` = %d",
		GarageInfo[gID][GarageOwner],
		GarageInfo[gID][ExtX],
		GarageInfo[gID][ExtY],
		GarageInfo[gID][ExtZ],
		GarageInfo[gID][ExtA],
		GarageInfo[gID][IntX],
		GarageInfo[gID][IntY],
		GarageInfo[gID][IntZ],
		GarageInfo[gID][IntA],
		GarageInfo[gID][vWorld],
		GarageInfo[gID][IntID],
		GarageInfo[gID][Status],
		GarageInfo[gID][ForSale],
		GarageInfo[gID][Price],
		gID
	);
	return mysql_tquery(g_iHandle, query);
}
Код:
(error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''Nc' at line 1
Reply
#9

You are missing value for `hID`., also you are saving the increment id to GarageInfo[gID][GID], then why you are saving with gID.

PHP код:
Garage_Save(gID)
{
    static
        
query[2048];
    
format(query,sizeof(query), "UPDATE `garages` SET `hID` = %d, `GarageOwner` = '%s', `GaragePosX` = %f, `GaragePosY` = %f, `GaragePosZ` = %f, `GaragePosA` = %f, `GarageIntX` = %f,`GarageIntY` = %f, `GarageIntZ` = %f, `GarageIntA` = %f, `VirtualWorld` = %d, `Interior` = %d, `Status` = %d, `ForSale` = %d, `Price` = %d WHERE `gID` = %d",
        
GarageInfo[gID][GarageOwner],
        
GarageInfo[gID][ExtX],
        
GarageInfo[gID][ExtY],
        
GarageInfo[gID][ExtZ],
        
GarageInfo[gID][ExtA],
        
GarageInfo[gID][IntX],
        
GarageInfo[gID][IntY],
        
GarageInfo[gID][IntZ],
        
GarageInfo[gID][IntA],
        
GarageInfo[gID][vWorld],
        
GarageInfo[gID][IntID],
        
GarageInfo[gID][Status],
        
GarageInfo[gID][ForSale],
        
GarageInfo[gID][Price],
        
GarageInfo[gID][GID]
    );
    return 
mysql_tquery(g_iHandlequery);

Reply
#10

gID and GarageInfo[gID][GID] are the same thing pretty much.

Okay. Thank you! I'm not getting any error messages in the code now. However still the only thing saving is the ForSale that is set when creating the row.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)