Search code examples
phpformsecho

PHP - Echoing Value for Input Form


I have this strange issue whereby my echo isn't showing the entire string.

I'm building an account form that auto populates the values with the user's already existing data.

$full_name = "Joe Smith";
echo $full_name;

Works fine. But as soon as I echo this into the html form as an input value, it only shows 'Joe', as if it ignores anything after a space.

<div class="input-item input-with-label">
    <label for="full-name" class="input-item-label">Full Name</label>
    <input class="input-bordered" type="text" id="full-name" name="full-name" value= <?php echo $full_name;?> >
</div>

This will show as 'Joe'.

I tried removing the PHP entirely, and just did a html tag of

value="Joe Smith"

And that shows fine. Any ideas as to why this is?


Solution

  • Please add " " quotes on value.

    Try this one:

    <div class="input-item input-with-label">
        <label for="full-name" class="input-item-label">Full Name</label>
        <input class="input-bordered" type="text" id="full-name" name="full-name" value="<?php echo $full_name;?>">
    </div>