tags:

views:

103

answers:

3

when i write

input data: hel'l"lo

print_r($_POST) display hel\'\"lo

and when i use

if(get_magic_quotes_gpc()){ 
    mysql_real_escape_string($_POST); 

display

hel\\\'\\\"lo

now my quetion is that "is it necessary to use mysql_real_escape_string? bcoz i think php automaticaaly add slashes in post varaiable?"

+1  A: 

magic_quotes_gpc is deprecated option at php 5.3

nex2hex
so what should i do??shoud i use `mysql_real_escape_string($_POST);`or not?
diEcho
yes, u must use it
nex2hex
A: 

No, from version 5.3 onwards, there will be no slashes added by default.

Sarfraz
so i have to use `mysql_real_escape_string($_POST);`
diEcho
yes you can use that :)
Sarfraz
A: 

is it necessary to use mysql_real_escape_string?

Yes. But not as a blanket encoding over $_POST or $_GET. That's applying an output-stage escaping mechanism to the input stage, which is the wrong thing and will mangle your strings in unexpected and unwanted ways.

You should keep your strings in raw form up until the moment you insert the string into another context. At that point only, you use the appropriate escaping function. With MySQL:

$query= "SELECT * FROM items WHERE title='"+mysql_real_escape_string($_POST['title'])+"'";

or with HTML:

<p>Title: <?php echo(htmlspecialchars($_POST['title'])) ?></p>
bobince