Page 1 of 1

Adding Quotes to input boxes

Posted: Fri Apr 08, 2005 7:49 am
by scudz
I have a problem when a user enters quotes into my text boxes.

if the user submits the form with the title as eg 'hel"lo wo"rld' and i echo it on my page, it will echo correctly as 'hel"lo wo"rld'. however, if the user goes back into the form to edit the variable from the database, the value of the box is 'hel.

i have tried the following to get it to work, but it doesnt seem to help any.
prints out \'hel\ into the text box.

Code: Select all

$q = mysql_query(&quote;SELECT title FROM inventory WHERE id=$id&quote;) or die(mysql_error());
$data = mysql_fetch_object($q);
$title = addslashes($data->title);

<input type=&quote;text&quote; name=&quote;title&quote; size=&quote;35&quote; value=&quote;<?= $title ?>&quote; />
any help would be appreciated.. im still learning this php stuff :)

Posted: Fri Apr 08, 2005 7:58 am
by Chris Corbyn

Posted: Fri Apr 08, 2005 8:05 am
by scudz
i did addslashes and i pasted what the result was

Code: Select all

//result of adding addslashes
\'hel\
something to do with the input box ?

works fine in textarea, just not input type="text"

Posted: Fri Apr 08, 2005 8:08 am
by anjanesh
When retriving from the db do a stripslashes()

Code: Select all

$title = stripslashes($data->title);
<input type="text" name="title" size="35" value="<?= $title ?>" />

Posted: Fri Apr 08, 2005 8:20 am
by scudz
output when using stripslashes:

'hel

Seems to die out when it hits the "..

Posted: Fri Apr 08, 2005 8:24 am
by scudz
added this code when inserting into the database seems to work :|

Code: Select all

$title = str_replace ( &quote;\&quote;&quote;, &quote;&quot;&quote;, $title ) ;