cotarider Posted February 18, 2008 Share Posted February 18, 2008 I have a page which I want to use to edit records in a MySQL table. The SQL part works fine but when I use echo to put the current values into an input box it only displays the data up to the first space. If as a test I just put echo and the variable name, I get all of the value displayed. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 18, 2008 Share Posted February 18, 2008 Do you have a character restriction on your input box? Quote Link to comment Share on other sites More sharing options...
mem0ri Posted February 18, 2008 Share Posted February 18, 2008 You say the data stores in the SQL table correctly? In my experience, that usually happens when you don't quote your strings correctly with an INSERT or UPDATE statement (it'll cut off at first space when going into the table...thus it gets only the first part when you display). Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 18, 2008 Share Posted February 18, 2008 You say the data stores in the SQL table correctly? In my experience, that usually happens when you don't quote your strings correctly with an INSERT or UPDATE statement (it'll cut off at first space when going into the table...thus it gets only the first part when you display). They said if they echo it in another place in the script they get the full value, so I don't think thats the problem. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 18, 2008 Share Posted February 18, 2008 Erm... <?php $str = "This is a string"; echo $str; // echo full string echo " <input type='text' value=$str>"; // truncates echo " <input type='text' value='$str'>"; // ok ?> Quote Link to comment Share on other sites More sharing options...
cotarider Posted February 18, 2008 Author Share Posted February 18, 2008 Barand you are a genius. I assumed it was a simple syntax problem I am the most dangerous type of programmer, self taught. Thank you to everyone who took the time to answer. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 18, 2008 Share Posted February 18, 2008 You have to be careful here. If the value of your $str contains a single quote, the above solution will break. To be perfectly safe, use the htmlentities() function with the ENT_QUOTES option: <?php echo " <input type='text' value='" . htmlentities($str,ENT_QUOTES) . "'>"; ?> Ken Quote Link to comment 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.