Shaun
Shaun

Reputation: 2311

Quotes problem text box

I have a text box like ,

<!--<input type="text"  maxlength="255" name="$key" value="<?php echo $value;?>"  />-->

$value is b'bbb"bbb

But it only shows b'bbb as value.Can any1 help ???

Upvotes: 1

Views: 1442

Answers (3)

Hemamalini
Hemamalini

Reputation: 751

you can use htmlentities() to use single and double quotes inside the textbox or when using session values

Upvotes: 0

damusnet
damusnet

Reputation: 4398

Obviously the " in your $value is breaking the html.

Try echo htmlspecialchars($value);

Upvotes: 0

Lekensteyn
Lekensteyn

Reputation: 66465

Properly escape your data that should be displayed unparsed in HTML using htmlentities():

<input type="text"  maxlength="255" name="<?php echo htmlentities($key);?>" value="<?php echo htmlentities($value);?>"  />

The quote char (") is breaking your code. It could get more dangerous if you've a $value like "><script>alert("xss")</script> (it's called XSS and will pop up an alert box with "xss")

Upvotes: 5

Related Questions