Jump to content

Calling a session variable doesnt show data after a space!


stevemreid

Recommended Posts

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
Share on other sites

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 <<<HTML
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>
HTML;
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.