SA-MP Forums Archive
Saving a string to MySQL - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Saving a string to MySQL (/showthread.php?tid=636339)



Saving a string to MySQL - UnlikePluto - 25.06.2017

Код:
SaveSQLStr(HouseData[houseid][HouseID], "houses", "OwnerName", HouseData[houseid][HouseOwnerName]);
I use this line of code to save the owners name to MySQL.

Here's my SaveSQLStr :

Код:
Server:SaveSQLStr(sqlid, table[], row[], value)
{
	new query[500];
	mysql_format(sqlBaglanti, query, sizeof query, "UPDATE %e SET %e = '%s' WHERE id = '%i'", table, row, value, sqlid);
	mysql_pquery(sqlBaglanti, query);
	return true;
}
But strangely it adds another letter to the name.

For example, if the owners name is "Harold Kingston". It saves it like this: "HHarold Kingston". I couldn't figure out what is wrong.


Re: Saving a string to MySQL - Vince - 25.06.2017

How is this not giving you any errors or warnings while compiling? And if it does, why are you ignoring them? The "value" parameter should be declared as an array but it is not.

Also I hope you don't have 20 of those "SaveSQL_" statements beneath each other because that would be very inefficient.


Re: Saving a string to MySQL - Abagail - 25.06.2017

Another thing, you ironically escape everything but the value you're setting, which is likely to at times be user input (password, etc). Change %s to %e, seriously.


Re: Saving a string to MySQL - UnlikePluto - 25.06.2017

Quote:
Originally Posted by Vince
Посмотреть сообщение
How is this not giving you any errors or warnings while compiling? And if it does, why are you ignoring them? The "value" parameter should be declared as an array but it is not.

Also I hope you don't have 20 of those "SaveSQL_" statements beneath each other because that would be very inefficient.
Well i get no errors or warnings while compiling. I updated the value parameter to an array. Didn't work. No worries i don't have it like that.

Quote:
Originally Posted by Abagail
Посмотреть сообщение
Another thing, you ironically escape everything but the value you're setting, which is likely to at times be user input (password, etc). Change %s to %e, seriously.
Changed it still not working.


Re: Saving a string to MySQL - Abagail - 25.06.2017

Add a print statement with the query string.


Re: Saving a string to MySQL - skuller12 - 25.06.2017

Код:
SaveSQLStr(HouseData[houseid][HouseID], "houses", "OwnerName", HouseData[houseid][HouseOwnerName]);

Server:SaveSQLStr(sqlid, table[], row[], value)
{
	new query[500];
	mysql_format(sqlBaglanti, query, sizeof query, "UPDATE %e SET %e = '%s' WHERE id = '%i'", table, row, value, sqlid);
	mysql_pquery(sqlBaglanti, query);
	return true;
}

'value' is not a type string

And replace with:

SaveSQLStr(HouseData[houseid][HouseID], "houses", "OwnerName", houseid);

Server:SaveSQLStr(sqlid, table[], row[], value)
{
	new query[500];
	mysql_format(sqlBaglanti, query, sizeof query, "UPDATE `%s` SET `%s` = '%s' WHERE `id` = '%d'", table, row, value, sqlid);
	mysql_tquery(sqlBaglanti, query, "", "");
	return true;
}