Input box's value shows only partial value

Hi everyone,
The following code is aimed to show “aaa aaa” as default value for input box in a form:

<?php //xxx.php
	$db = mysqli_connect('localhost', '', '', '');
?>
<!DOCTYPE html>
<html>
<body>
	<form method="POST" action="xxx.php">
		<input type="text" name="id" class="id_input" value=<?php echo 'aaa aaa';?>>
	</form>		
</body>
</html>

When I run it, the default value in the “value” attribute for the input box shows “aaa”.
Can anyone explain me why?
Why doesnt the the default value inserted to “value” attribute as “aaa aaa” sohow “aaa aaa”?!
Thanks !

Missing quotes around the value parameter. You’ve put double-quotes around the rest of the values on that line, do the same with value. It sees the space in the string as the end of the value, and ignores the second “aaa”. View the HTML source in your browser to see.

Incidentally this is nothing to do with you echoing it from PHP, it would do the same if it was plain HTML.

2 Likes

Thanks a lot !

Based on the code posted there is no need to use Php to echo the value, just put it in there.

True, but I’m guessing that’s not the whole story. Probably the sting is standing in for a variable that will contain a string.
But still, as @droopsnoot pointed out, this is not really a php problem at all, it’s just incorrect html syntax.

The original code displays a table of a “select” result.
Each line can be edited by clicking the “edit” button.
In that case I want that line of the table to be a form with input boxes containing the original values of the line “clicked”.
The values were only partially displayed and I wondered why.
Sending the whole php/MySQL/html/css code wouldn’t be useful so I worked hard to extract the core of the problem.
Thank you anyway

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.