It’s never useless, because you never know what is passed to the script. Of course, it’s not always the best thing to do. If the value should always be numeric, for example, you can check it with (int) to force it to be numeric.
Guido, you just don’t understand what this function do.
It’s terrible mistake and I am sure you will learn the right way.
because you never know what is passed to the script
Right.
It’s never useless,
Wrong. Without quotes it is nothing. The key word is “without quotes”. Escaping and quotes are 2 parts of one mechanism. mysql_real_escape_string without quotes as useless as quotes without mysql_real_escape_string.
Hey Doug, try second one Guido’s code.
For the mysql_error() function in it.
Or just add these lines at the bottom of your code:
Oh. As simple injection as
id=1 or 1
mysql_real_escape string will not harm this text.
But id=‘1 or 1’ will be cast to id=‘0’
When we assume incoming data as string, both quotes and escaping must be used.
mysql_real_escape_string alone can help nothing