Page 1 of 1

String didnt echo completely

Posted: Mon Dec 28, 2009 11:30 am
by kingdm
I fetch a value from my database table named 'spouse' which has a value of "Elizabeth Jik", and stored it in a session variable named $_SESSION['spouse'].

Now I try to output the value in a input type text field. Here is my code:

Code: Select all

 
<?php 
session_start(); 
$spouse = $_SESSION['spouse']; 
if($_SESSION['cstatus'] == 'Married') 
        { 
            $display_spouse = "<input type=\"text\" name=\"spouse\" maxlength=\"80\" value=".$spouse." >"; 
        } 
?> 
<html> 
. 
. 
. 
<div> 
<?php echo $display_spouse; ?> 
</div> 
. 
. 
. 
</html>
 
The code works and it does output a value, however, it only prints Elizabeth. The surname Jik is missing. Why is that?

Re: String didnt echo completely

Posted: Mon Dec 28, 2009 12:11 pm
by AbraCadaver
Probably because you haven't quoted the value. May work sometimes, but probably not when there is a space:

Code: Select all

$display_spouse = "<input type=\"text\" name=\"spouse\" maxlength=\"80\" value=\"".$spouse."\">";