How to add/allow special characters in mysql – php data interchange

To prepare data for insertion to a text field in MySQL via PHP use the
following function;

$raw_additional_notes=$_POST['additional_notes'];
$additional_notes = mysql_escape_string($raw_additional_notes);    ///to escape the special charecters		
and to get it back to normal after reading it from the database...
$raw_additional_notes= stripslashes($additional_notes);

Basically the special characters are allowed in mysql with backslaches (“\”) therefore to add any such charectar, string needs to rewritten according to mysql. Using mysql_escape_string() function  the slashes can be added in string.

stripslashes() can revert back the same string deleting slashes.


 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s