mysql-real-escape-string adds backslashes and rn

Hi all,

I am having a problem with my PHP form. Users enter comment in the comments box and when my php script processes the comments variable, it adds backslashes. How do I remove backslashes? I tried using stripslashes function but it started generating MySQL error.

Here is the variable look like in the PHP script:

$comments = mysql_real_escape_string($_POST[‘comments’]);

The “$comments” variable is passed to an email and also stored in MySQL database. Please help!

Its adding them because you’re telling it to. That’s what mysql_real_escape_string does and you’re getting errors because any rogue quotes can prematurely end a string, causing all sorts of problems.

When you display the comment, that’s when you use stripslashes.

Sponsor our Newsletter | Privacy Policy | Terms of Service