user188962
user188962

Reputation:

double quotes makes text dissappear, why?

Whenever the texts value has double-quotes, everything behind and including the double-quotes dissappear.

Ex: Nice bmw m3 with 19" wheels BECOMES Nice bmw m3 with 19 the part after the double-quotes is skipped.

Is there anyway around this?

About the code below: This is for a form on a php page, so when the form is submitted to itself the value of the input remains unchanged, so the user doesn't have to fill in everything again whenever form is submitted to self.

<input style="width:300px;" type="text" name="annonsera_headline" id="annonsera_headline" value="<?php echo @$_POST['annonsera_headline'];?>">

Thanks

Upvotes: 1

Views: 159

Answers (3)

me_an
me_an

Reputation: 509

   ... value = "htmlentities(<?=$_POST['annonsera_headline']?>)"

Upvotes: 0

Yacoby
Yacoby

Reputation: 55465

Because " ends the value of the html attribute.

Use htmlentities or htmlspecialchars

value="<?php echo htmlentities(@$_POST['annonsera_headline']);?>">

It is not advisable to write values from $_POST or $_GET without using at least one of the above functions as otherwise it allows people to construct a URL that alters the HTML on your page.

Upvotes: 3

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799430

You forgot to sanitize the value with htmlentities().

Upvotes: 2

Related Questions