3

I have a simple HTML form with multiple input tags. On page load i provide data to the form to echo the current value of field from database and than user can modify those values and submit again to perform an update.

<input type="text" name="nameMember" id="nameMember" value=<?php echo (isset($nameMember)) ? $nameMember: ''?>>

Code works fine except that it do not display complete variable.

For example, If $nameMember = 'Saurabh Pradhan' than instead of showing 'Saurabh Pradhan' as value of input tag it only shows 'Saurabh'.

If i remove the space from the data and make it to 'SaurabhPradhan' it displays complete name. Basically it is only removing the text after space.

Saurabh
  • 664
  • 2
  • 12
  • 30

3 Answers3

4

HTML attribute values should generally be wrapped in quotes:

<input type="text" name="nameMember" id="nameMember" value="<?php echo (isset($nameMember)) ? $nameMember: ''?>">

exactly as you already do with the type and name attributes

The value attribute is no different

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
1

You forget to add quotes in value attribute like value="" in quotes echo your variable ,in HTML quotes generate automatically and if space found attribute automatically close quotes after space

 value="<?php echo (isset($nameMember)) ? $nameMember: ''?>"
Maninderpreet Singh
  • 2,569
  • 2
  • 17
  • 31
1

Put quotes around your echo

value="<?php echo (isset($nameMember)) ? $nameMember: ''?>"
Jay Mason
  • 446
  • 3
  • 17