Reputation: 22715
I have this code basis:
echo '<input required type = "text" name = "subject1" value="XXX" />';
However, I would like XXX to be a variable, I have searched this online, but all the things that one of the discussions says is to do this:
value=\"$firstName\"
or
value='$firstName'
I have tried both of these, but they don't work, and I was hoping that someone could help me with this problem, basically, what I want is to be able to asign the value of a text edit to a variable in php, but when the text edit itself, is embedded in an echo, nothing seems to work.
Thanks
Upvotes: 2
Views: 19534
Reputation: 58601
I think the problem is you are using single quotes, so variables are not rendered automatically... you can concat with .
like this:
echo 'some text' . $variable . 'some more text';
Upvotes: 3
Reputation: 6786
echo '<input required type="text" name = "subject1 value="<?php echo $value; ?>" />';
acutally you don't need the php echo .... stuff.... /* brain not engaged */
Upvotes: 1
Reputation: 2837
Concatenation is a pretty easy way to go about this:
echo '<input required type = "text" name = "subject1" value="' . $foo . '" />'
edit: Those spaces around the concatenation .'s (. $foo .
) aren't required - I just add them fore readability.
Upvotes: 4