Jump to content

[SOLVED] white space creating problems in session variables


mubashir

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.

Archived

This topic is now archived and is closed to further replies.

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