Can't get this code right

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
User avatar
Lonestarjack
Forum Commoner
Posts: 31
Joined: Tue Nov 11, 2008 7:13 am
Location: Texas

Can't get this code right

Post by Lonestarjack »

What is the correct code ?

Code: Select all

<?php echo '<input class="x"  
	onfocus="HideContent("btn")" 
	name="username" 
	type="text" 
	id="username" 
	value= ' . $user . ' >';
	?>
It seems to fail around "btn" with a parse error.
$user has been defined.
HideContent is already defined.
Last edited by Benjamin on Thu Oct 06, 2011 9:19 am, edited 1 time in total.
Reason: Added [syntax=php|sql|css|javascript] and/or [text] tags.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Can't get this code right

Post by Celauran »

Code: Select all

<?php

echo "<input class=\"x\"  
        onfocus=\"HideContent('btn');\" 
        name=\"username\" 
        type=\"text\" 
        id=\"username\" 
        value=\"{$user}\" />";

?>
User avatar
egg82
Forum Contributor
Posts: 156
Joined: Sat Oct 01, 2011 9:29 pm
Location: Colorado, USA

Re: Can't get this code right

Post by egg82 »

Code: Select all

echo '<input class="x"  
         onfocus="HideContent(\'btn\');" 
         name="username" 
         type="text" 
         id="username" 
         value="{$user}" />';
Keep it simple :P
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Can't get this code right

Post by Celauran »

egg82 wrote:

Code: Select all

echo '<input class="x"  
         onfocus="HideContent(\'btn\');" 
         name="username" 
         type="text" 
         id="username" 
         value="{$user}" />';
Keep it simple :P
Except your code doesn't work. Can't evaluate variables inside single quotes.

Code: Select all

echo '<input class="x"  
         onfocus="HideContent(\'btn\');" 
         name="username" 
         type="text" 
         id="username" 
         value="' . $user . '" />';
User avatar
egg82
Forum Contributor
Posts: 156
Joined: Sat Oct 01, 2011 9:29 pm
Location: Colorado, USA

Re: Can't get this code right

Post by egg82 »

whoops, my bad! Thanks
Post Reply