sscanf not working with mysql
#7

Quote:
Originally Posted by Aldo.
Посмотреть сообщение
Query was incorrect
pawn Код:
format(query2, 256, "SELECT * FROM users WHERE username='%s'", playername2);
mysql_real_escape_string(query2); // Prevents SQL injection
I think you'll find that escaping the entire query is not a form of prevention against SQL injection, but is actually a form of breaking the query, you're not supposed to escape the query, you're supposed to escape values that are being inserted into the query string that are controlled by the player. For example:

pawn Код:
mysql_real_escape_string(playername2,playername2);
format(query2, sizeof(query2), "SELECT * FROM `users` WHERE Username = '%s'", playername2);
This will escape the players name, so any characters that may be used in the name to inject their own code will be escaped, for example, if the players name was

Код:
';DROP *;
it will now become

Код:
\'DROP *;
so the character is escaped, not allowing the person to inject code.

With that said, it's not even possible to inject code using a name, because you can't even play SA-MP with those characters in your nickname.
Reply


Messages In This Thread
sscanf not working with mysql - by SaW_[VrTx] - 26.04.2011, 14:39
Re: sscanf not working with mysql - by Alby Fire - 26.04.2011, 14:56
Re: sscanf not working with mysql - by Aldo. - 26.04.2011, 15:29
Re: sscanf not working with mysql - by Alby Fire - 26.04.2011, 15:40
Re: sscanf not working with mysql - by [NoV]LaZ - 26.04.2011, 15:50
Re: sscanf not working with mysql - by MadeMan - 26.04.2011, 16:35
Re: sscanf not working with mysql - by JaTochNietDan - 26.04.2011, 16:37
Re: sscanf not working with mysql - by SaW_[VrTx] - 26.04.2011, 18:48
Re: sscanf not working with mysql - by Raimis_R - 26.04.2011, 18:55

Forum Jump:


Users browsing this thread: 3 Guest(s)