stevemreid Posted July 25, 2006 Share Posted July 25, 2006 Hey all,Im a newb and have came across a problem which I hope you guys can help with. I've got a form that submits some info into a mysql database. It works and all the data goes into the database, and once you have submitted your info on the form you can press a button on the form page which loads the previously submitted values back into the form. It nearly works in that it returns all the data unless theres a space in it - i.e if one form field contains the word "Jones" it will return it , but if it was "Mr Jones" it would only return "Mr".Heres some code if its needed:On the php page that "inserts" the data into the database I have this:$address4=$_POST['address4'];$postcode=$_POST['postcode'];then//put all the variables into a session variable so there accesible across the whole site foreach($_POST as $key => $value) $_SESSION[$key] = $value;Once you press the button to reload the previous values the code to populate the form is :<td><strong>Address 4</strong></td> <td><input name='address4' type='text' id='address4' value=$_SESSION[address4]></td> </tr> <tr> <td><strong>Postcode<span class='rederror'>*</span></strong></td> <td><input name='postcode' type='text' id='postcode' value=$_SESSION[postcode]></td> </tr> <tr> The mysql table fields in question are varchars.Could someone point me in the right direction?Thanks!Steve Link to comment https://forums.phpfreaks.com/topic/15567-calling-a-session-variable-doesnt-show-data-after-a-space/ Share on other sites More sharing options...
wildteen88 Posted July 25, 2006 Share Posted July 25, 2006 You need to surround the value of of the value attribute with quotes:[code]<input name='postcode' type='text' id='postcode' value="{$_SESSION['postcode']}">[/code]Also i you start your echo statement with an " then you'll need to escape any instance of " within your echo statament, apart from the ending ". Like so:[code]echo "<input name=\"postcode\" type=\"text\" id=\"postcode" value=\"{$_SESSION['postcode']}\">";[/code]Or if you are echoing out large chuncks of HTML use HEREDOC:[code]echo <<<HTMLtd><strong>Address 4</strong></td> <td><input name="address4" type="text" id="address4" value="{$_SESSION['address4']}"></td> </tr> <tr> <td><strong>Postcode<span class="rederror">*</span></strong></td> <td><input name="postcode" type="text" id="postcode" value="{$_SESSION['postcode']}"></td> </tr> <tr>HTML;[/code] Link to comment https://forums.phpfreaks.com/topic/15567-calling-a-session-variable-doesnt-show-data-after-a-space/#findComment-63310 Share on other sites More sharing options...
stevemreid Posted July 25, 2006 Author Share Posted July 25, 2006 So simple when you know how but I may not have ever worked it out by myself.Thank you so much!Steve Link to comment https://forums.phpfreaks.com/topic/15567-calling-a-session-variable-doesnt-show-data-after-a-space/#findComment-63334 Share on other sites More sharing options...
wildteen88 Posted July 25, 2006 Share Posted July 25, 2006 No problem, Its a common problem most new comers face, I even fell into the same trap too when I started. Link to comment https://forums.phpfreaks.com/topic/15567-calling-a-session-variable-doesnt-show-data-after-a-space/#findComment-63389 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.