Jump to content


Photo

Calling a session variable doesnt show data after a space!


  • Please log in to reply
3 replies to this topic

#1 stevemreid

stevemreid
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 25 July 2006 - 10:06 AM

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


#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 July 2006 - 11:01 AM

You need to surround the value of of the value attribute with quotes:
<input name='postcode' type='text' id='postcode' value="{$_SESSION['postcode']}">

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:
echo "<input name=\"postcode\" type=\"text\" id=\"postcode" value=\"{$_SESSION['postcode']}\">";
Or if you are echoing out large chuncks of HTML use HEREDOC:
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;


#3 stevemreid

stevemreid
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 25 July 2006 - 12:09 PM

So simple when you know how but I may not have ever worked it out by myself.
Thank you so much!
Steve

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 July 2006 - 02:04 PM

No problem, Its a common problem most new comers face, I even fell into the same trap too when I started.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users