SQL not saving
#1

Hi, I have this three functions to save different values, the SaveSQLInt works perfect, but the problem is with the SaveSQLFloat and SaveSQLString, those aren't saving the values...

Код:
Servidor:SaveSQLInt(sqlid, table[], row[], value)
{
	new query[128];
	mysql_format(sqlConnection, query, sizeof(query), "UPDATE %e SET %e = %i WHERE id = %i", table, row, value, sqlid);
	mysql_pquery(sqlConnection, query);
	return true;
}

Servidor:SaveSQLFloat(sqlid, table[], row[], Float:value)
{
	new query[128];
	mysql_format(sqlConnection, query, sizeof(query), "UPDATE %e SET %e = %f WHERE id = %i", table, row, value, sqlid);
	mysql_pquery(sqlConnection, query);
	return true;
}

Servidor:SaveSQLString(sqlid, table[], row[], value[])
{
	new query[128];
	mysql_format(sqlConnection, query, sizeof(query), "UPDATE %e SET %e = %s WHERE id = %i", table, row, value, sqlid);
	mysql_pquery(sqlConnection, query);
	return true;
}
Reply
#2

Have you looked at the way you use these functions ?
Tried to use the functions directly ?
pawn Код:
SaveSQLFloat(0,"accounts","Antenastyle",2.00);
SaveSQLString(0, "table","Antenastyle", "String");
Maybe the issue isn't in the functions at all.

Try to print whether mysql_pquery returns 1 (for successful) or 0
Reply
#3

Okay, the floats saves right, but the string isn't saving, I'm doing this...

Код:
else if(strmatch(section, "name"))
		{
			if(sscanf(params, "s[10]s[40]", section, extra)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: {FFFFFF}/edithouse name [Name]");
			{
				if(strlen(extra) < 3 || strlen(extra) > 39) return SendClientMessage(playerid, COLOR_ERROR, "ERROR: Name must be between  3 and 39 characters.");
				
				HouseData[houseid][HouseName] = extra;
				
				Delete3DTextLabel(HouseData[houseid][HouseLabel]);
				if(HouseData[houseid][HouseOwnerSQL] != 0)
				{
					format(string2, sizeof(string2), "{FFCC00}%s\nID: {FFFFFF}%i", HouseData[houseid][HouseName], HouseData[houseid][HouseSQLId]);
				}
				else
				{
					format(string2, sizeof(string2), "{FFCC00}%s\nPrice: {FFFFFF}%i$\n{FFCC00}ID: {FFFFFF}%i", HouseData[houseid][HouseName], HouseData[houseid][HousePrice], HouseData[houseid][HouseSQLId]);
				}
				HouseData[houseid][HouseLabel] = Create3DTextLabel(string2, 0xFFFFFFFF, HouseData[houseid][HouseExterior][0], HouseData[houseid][HouseExterior][1], HouseData[houseid][HouseExterior][2], 10.0, 0, 1);
				
				SaveSQLString(HouseData[houseid][HouseSQLId], "houses", "Name", HouseData[houseid][HouseName]);
				
				SendClientMessage(playerid, COLOR_YELLOW, "INFO: Name edited:");
				SendClientMessage(playerid, COLOR_WHITE, HouseData[houseid][HouseName]);
			}
		}
HouseData[houseid][HouseName] changes, but it is not being saved into the db
Reply
#4

Then it could be the type of the column that is doing the mess.

Check if the column type is set to varchar(40) (or TEXT, but varchar(40) is prefered)
Reply
#5

The column is set to varchar(40)
Reply
#6

pawn Код:
UPDATE %e SET %e = %s WHERE id = %i
You didn't do ''
pawn Код:
UPDATE %e SET %e = '%s' WHERE id = %i
That's why.
Reply
#7

Tell me why u r escaping the table and row but not value?

mysql_format(sqlConnection, query, sizeof(query), "UPDATE %e SET %e = %s WHERE id = %i", table, row, value, sqlid);
Reply
#8

Quote:
Originally Posted by Kaperstone
Посмотреть сообщение
pawn Код:
UPDATE %e SET %e = %s WHERE id = %i
You didn't do ''
pawn Код:
UPDATE %e SET %e = '%s' WHERE id = %i
That's why.
Thank you, that was the problem, now works perfect!

Quote:
Originally Posted by Meller
Посмотреть сообщение
Tell me why u r escaping the table and row but not value?

mysql_format(sqlConnection, query, sizeof(query), "UPDATE %e SET %e = %s WHERE id = %i", table, row, value, sqlid);
What do you mean?
Reply
#9

Quote:
Originally Posted by Antenastyle
Посмотреть сообщение
What do you mean?
You're securing the table and row by using %e, but then you let the value go unsecured as a normal string, do this:
PHP код:
mysql_format(sqlConnectionquerysizeof(query), "UPDATE %e SET %e = '%e' WHERE id = %i"tablerowvaluesqlid); 
instead of
PHP код:
mysql_format(sqlConnectionquerysizeof(query), "UPDATE %e SET %e = %s WHERE id = %i"tablerowvaluesqlid); 
Reply
#10

Quote:
Originally Posted by Meller
Посмотреть сообщение
You're securing the table and row by using %e, but then you let the value go unsecured as a normal string, do this:
PHP код:
mysql_format(sqlConnectionquerysizeof(query), "UPDATE %e SET %e = '%e' WHERE id = %i"tablerowvaluesqlid); 
instead of
PHP код:
mysql_format(sqlConnectionquerysizeof(query), "UPDATE %e SET %e = %s WHERE id = %i"tablerowvaluesqlid); 
Yeah, I've changed it, thank you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)