String didnt echo completely

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kingdm
Forum Commoner
Posts: 27
Joined: Thu Dec 03, 2009 9:32 am

String didnt echo completely

Post 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?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: String didnt echo completely

Post 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."\">";
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply