I'm trying to put a php variable in the value of a radio input field but can't get the syntax correct:
echo '<input type="radio" name="textcat" value=" 'textCats[0])' " checked = "checked"/> biography';
thanks for you assistance
php in an input field
Moderator: General Moderators
Re: php in an input field
Code: Select all
echo "<input type=\"radio\" name=\"textcat\" value=\"{$textCats[0]}\ " checked = \"checked\"/> biography";
or
echo '<input type="radio" name="textcat" value="' . $textCats[0]) . ' " checked = "checked"/> biography';
Re: php in an input field
I probably should have given the complete context which is as follows:
// It still comes up with a parse error:
Parse error: syntax error, unexpected '[', expecting ',' or ';' in /Users/garylee/Desktop/
If I replace the textCats[0] with $textCats, however, there is no error. So how do I include a subscripted variable?
thanks
Code: Select all
echo '<form id="form2" name="form1" method="post" action="textEdit.php">';
if ($_POST['textcat']== $textCats[0]){
echo '<input type="radio" name="textcat" value=" '.textCats[0].' " checked = "checked" /> biography';
} else {
echo '<input type="radio" name="textcat" value=" '.textCats[0].' " /> biography';
}
Parse error: syntax error, unexpected '[', expecting ',' or ';' in /Users/garylee/Desktop/
If I replace the textCats[0] with $textCats, however, there is no error. So how do I include a subscripted variable?
thanks
Re: php in an input field
Okay, thank you for the suggestion of adding the dots as in .textCats[0]. That was one of my mistakes. The other was proobably too obvious to recognize but it should have been .$textCats[0]. as that was the previously defined array... der all work and no play makes Gary a dull boy.
thanks again
thanks again