0

I'm getting a problem with saving input to my DB.

I save my string to my DB as:

mysql_real_escape_string($my_string)

Then, I read and I place the string to the input using this:

stripslashes($my_string)

The point is, if I set double slashes into my string, the inputs crash like this:

<input maxlength = "150" type="text" name = "my_string12" value = "hello "this is" a test"  class="input-medium"/>

Thanks.

2 Answers2

0

If the value as PHP variable then you have to trim it ..

Use the trim function:

$str = 'hello "this is" a test';
echo trim($str, '"'); // hello this is a test

answered by paul at here

Community
  • 1
  • 1
matzone
  • 5,703
  • 3
  • 17
  • 20
0

You Can Use

<?php echo addslashes('hello "this is" a test'); // hello \"this is\" a test ?>

an stripslashes to remove it

<?php echo stripslashes('hello \"this is\" a test'); // hello "this is" a test ?>

or just type it like this

value = 'hello "this is" a test' or value = "hello 'this is' a test"