Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP echo inside input dont work?

<input name="name" type="text"  
       id="nome" size="45"  maxlength="35" value=<?php echo "need help" ?>/> 

// output "need" but i expect "need help"

it was a POST var string of a name, but just out puts the fist name, then i realised the echo or print do not work with whitespace inside the tag value, like echo do outside

what the solution to "need help"??

like image 230
Gualter Costa Avatar asked Dec 21 '13 03:12

Gualter Costa


2 Answers

Currently, your HTML mark up would look like:

<input name="name" type="text"  
           id="nome" size="45"  maxlength="35" value=need help/> 
                                               ^--------^

As it's evident from the syntax highlighting here, only need is considered as part of the value attribute. help is being considered as a separate new attribute.

You need quotes around the attribute value:

<input name="name" type="text"  
       id="nome" size="45"  maxlength="35" value="<?php echo "need help" ?>"/> 
                                                 ^                         ^ 
like image 123
Amal Murali Avatar answered Oct 15 '22 13:10

Amal Murali


try this code.

<input name="name" type="text"  
       id="nome" size="45"  maxlength="35" value="<?php echo 'need help'; ?>"/>
like image 26
newday Avatar answered Oct 15 '22 15:10

newday