Php – String Containing double quotes is inserted incomplete in DB

double-quotesescapingPHP

Updated
The textarea i have provided in the form takes the user input as strings

String Containing double quotes is inserted incomplete in DB..

I have a string inserted in text area as

"Don't worry too much about
layout/design/text size, we will often
"spice up" (i.e. bold, italic,
spacing) your banner for a better
overall look.

And when i inserted the string into DB the string get end at

Don't worry too much about
layout/design/text size, we will often

and is inserted partially.. What should i do to allow all the single and double quotes to be inserted?

EDIT ON REQUEST

Below Is the query I am using to insert in the database using php

"insert into products_description
(products_id, products_name,
products_logo_name1,
products_logo_name2,
products_logo_name3,
products_description) values ('" .
(int)$products_id . "', 'banner_" .
$products_id .
"','".$_POST['logoimage1']."',
'".$_POST['logoimage2']."',
'".$_POST['logoimage3']."',
'".mysql_real_escape_string($_POST['description'])."')"

Here mysql_real_escape_string($_POST['description']) is not escaping double quotes and hence truncates in insertion what should be done?

Best Answer

Escape the doublequotes inside the string, like so:

$theString = "Hello, i wonder what all these \"quotes\" are doing in here...";

The backslash will tell the compiler to ignore the "meaning" of the folowing doublequote, and treat it like a normal character (This is what we call "Escaping").

Also check out mysql_real_escape_string() when working with user input (This will automatically escape all dangerous elements in strings for use in a mySQL Database).