Adding Quotes to input boxes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scudz
Forum Newbie
Posts: 8
Joined: Tue Mar 08, 2005 4:27 am

Adding Quotes to input boxes

Post 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 :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

scudz
Forum Newbie
Posts: 8
Joined: Tue Mar 08, 2005 4:27 am

Post 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"
Last edited by scudz on Fri Apr 08, 2005 8:10 am, edited 1 time in total.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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 ?>" />
scudz
Forum Newbie
Posts: 8
Joined: Tue Mar 08, 2005 4:27 am

Post by scudz »

output when using stripslashes:

'hel

Seems to die out when it hits the "..
scudz
Forum Newbie
Posts: 8
Joined: Tue Mar 08, 2005 4:27 am

Post 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 ) ;
Post Reply