/> // pr...">

PHP echo inside input not working?

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

// print "need" but I expect "need help"

it was a string POST var of the name, but just gives the name of the fist, and then I realized that echo or print does not work with a space inside the tag value, for example, echo do outside

what solution "need help"

+4
source share
2 answers

Your HTML label will now look like this:

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

As can be seen from the syntax highlighting here, it is only needconsidered as part of the attribute value. helpconsidered 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" ?>"/> 
                                                 ^                         ^ 
+12
source

.

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

All Articles