Jump to content

Problem setting a string with " " as a default value for a form


AKalair

Recommended Posts

Hello,

 

I'm taking data stored in a database and setting it as the default value for a form.

 

However I have a problem if the data has a " in it then it wont appear as the default value.

 

For example This:

 

"virtually silent" some claim

 

Wont appear in the form box as a default value but without the " it will

 

Any ideas?

 

Thanks

 

You probably use in html also " (double quotes for fields) so

 

<input value="<?echo $value; ?>">

 

becomes

 

<input value=""virtualle silent"">

 

with doubled double quotes which breaks the mark up totally.

 

Or maybe post the code you have for the form and the code where you get the data from db for further examination.

This is the code I use to insert data into the database (with some cropping)

 

$newsstorytagline = str_replace("'","''",$_POST["tagline"]);
mysql_query("INSERT INTO news (userid, categoryid, newstitle, newstagline, newsbody, imageurl) VALUES ('$realuserid', '$categoryid', '$newsstorytitle', '$newsstorytagline', '$newsstory', '$imageurl') ") or trigger_error('Unable to Create News Story' , E_USER_ERROR);

 

Then this is how I recall it to be the default value

 

$getnewstaglineone = $getrealarticle['newstagline'];

<input type="text" name="tagline" size="50" value =" <?php echo "$getnewstaglineone" ?> " />

 

 

 

Thanks

 

Any time you output data that is not intended to be rendered as HTML to a web page that could contain HTML special characters (" in this case), you need to use htmlentities with the second parameter set to ENT_QUOTES so that the HTML special characters in it don't break the HTML on your page.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.