AKalair Posted September 15, 2009 Share Posted September 15, 2009 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 Link to comment https://forums.phpfreaks.com/topic/174325-problem-setting-a-string-with-as-a-default-value-for-a-form/ Share on other sites More sharing options...
TeNDoLLA Posted September 15, 2009 Share Posted September 15, 2009 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. Link to comment https://forums.phpfreaks.com/topic/174325-problem-setting-a-string-with-as-a-default-value-for-a-form/#findComment-918927 Share on other sites More sharing options...
AKalair Posted September 15, 2009 Author Share Posted September 15, 2009 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 Link to comment https://forums.phpfreaks.com/topic/174325-problem-setting-a-string-with-as-a-default-value-for-a-form/#findComment-918931 Share on other sites More sharing options...
PFMaBiSmAd Posted September 15, 2009 Share Posted September 15, 2009 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. Link to comment https://forums.phpfreaks.com/topic/174325-problem-setting-a-string-with-as-a-default-value-for-a-form/#findComment-918932 Share on other sites More sharing options...
AKalair Posted September 15, 2009 Author Share Posted September 15, 2009 Thank You! Link to comment https://forums.phpfreaks.com/topic/174325-problem-setting-a-string-with-as-a-default-value-for-a-form/#findComment-918936 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.