Page 1 of 1

php in an input field

Posted: Wed Nov 03, 2010 9:34 am
by chopWood
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

Re: php in an input field

Posted: Wed Nov 03, 2010 10:30 am
by yacahuma

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

Posted: Wed Nov 03, 2010 8:44 pm
by chopWood
I probably should have given the complete context which is as follows:

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';
	}
// 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

Re: php in an input field

Posted: Wed Nov 03, 2010 9:05 pm
by chopWood
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