Jump to content

Question about mysql_real_escape_string..


virtuexru

Recommended Posts

OK, so I have users write something. Then input it to a "wall post".. kinda like a flat message board.

 

However, since I use mysql_real_escape_string(); for the $_POST variable, when they use the ' character, posts come out jarbled like this:

 

" couldn\'t understand it, I\'m totally new to it"

 

Anyway to fix this or workaround?

Link to comment
https://forums.phpfreaks.com/topic/45056-question-about-mysql_real_escape_string/
Share on other sites

That would be magic_quotes, a php.ini setting... you can turn this off or run stripslashes before you use mysql_real_escape_string()

 

<?php
$variable = $_POST['variable'];

if(get_magic_quotes_gpc()) // For portability
{
     $variable = stripslashes($variable);
}

$variable = mysql_real_escape_string($variable);
?>

That would be magic_quotes, a php.ini setting... you can turn this off or run stripslashes before you use mysql_real_escape_string()

 

<?php
$variable = $_POST['variable'];

if(get_magic_quotes_gpc()) // For portability
{
     $variable = stripslashes($variable);
}

$variable = mysql_real_escape_string($variable);
?>

 

 

You mean stripslashes after not before? because before there are no slashes added, mysql_real_escape_string adds the slashes.. but will remove the slashes when you echo the data back on what ever page you do that on..

 

 

regards

Liam

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.