Jump to content

[SOLVED] white space creating problems in session variables


Recommended Posts

i use session variables to store values submitted by the form for later retrieval.. but once i try to retrieve the values they get truncated where ever the white space is encoutered... e.g. if i submit the  value as "blood sample"..  n store it in session variabl.. once i try to retrieve the value it shows "blood" only ... anything after the white space is ingnored or truncated...

code snippet is like  this ...

//storing the values...

$tname=$_POST['tstname'];

$_SESSION['testname']=$tname;

..

 

//retrieve values...

<input type ="text" name ="tstname" value =<?php echo $_SESSION['testname']; ?>>

.

.

any body knows wats the problem ...

thankx

 

Actually, the whole string is still inside your session variable its an HTML problem. Try:

 

<input type ="text" name ="tstname" value ="<?php echo htmlentities($_SESSION['testname']); ?>">

 

Note the double quotes. Without surrounding your value in quotes, how is a browser supposed to know when the value ends and the next property begins? Hence why it makes an educated guess, and uses spaces.

 

Also, ive added the htmlentities() function there - otherwse you'll run into issues if your variable contains double quotes.

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.