defeated Posted April 20, 2009 Share Posted April 20, 2009 Hi, I used mysql_real_escape_string() on my input. That worked fine. "What's my name?" turned into "What\'s my name?" and it inserted fine. When I look at the field in php my_admin though it is back to "What's my name?" When I try and output the field I get "What" I tried addslashes(), stripslashes() and even mysql_real_escape_string() again. Nothing worked. What am I doing wrong? I noticed the same thing happens on image captions in wordpress. There must be a simple solution? Quote Link to comment https://forums.phpfreaks.com/topic/154957-solved-cant-get-data-containing-single-quotes-out-of-db/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 21, 2009 Share Posted April 21, 2009 The HTML where you are displaying the retrieved information is incorrect. It is most likely missing quotes around the data value so the space serves as a stop character. Post your code that is displaying the results. Quote Link to comment https://forums.phpfreaks.com/topic/154957-solved-cant-get-data-containing-single-quotes-out-of-db/#findComment-815103 Share on other sites More sharing options...
defeated Posted April 21, 2009 Author Share Posted April 21, 2009 echo "<td><input name='myname' value='".$myname."' /></td>"; where $myname = "What's my name" ; I got it to work by doing the following: echo "<td>" ; ?> <input name="myname" value="<?php echo $myname ; ?>" /> <?php echo "</td>"; It's far from elegant though. So I'm not marking as solved yet until I see if someone has a better idea. Quote Link to comment https://forums.phpfreaks.com/topic/154957-solved-cant-get-data-containing-single-quotes-out-of-db/#findComment-815106 Share on other sites More sharing options...
PFMaBiSmAd Posted April 21, 2009 Share Posted April 21, 2009 In addition to having quotes around your value (which you already had), you need to use htmlentities on data your put into value="..." parameters so that any html special characters that might be in it don't break the HTML on your page. Quote Link to comment https://forums.phpfreaks.com/topic/154957-solved-cant-get-data-containing-single-quotes-out-of-db/#findComment-815134 Share on other sites More sharing options...
defeated Posted April 21, 2009 Author Share Posted April 21, 2009 htmlentities() .... always wondered what they were for! Learn something new every day. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/154957-solved-cant-get-data-containing-single-quotes-out-of-db/#findComment-815255 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.