Parse Error

I am getting a parse error that I am having a hard time nailing down.


$form="<form action='maintain.php' method='POST'>
	<TABLE>
		<TR>
			<TD><label for='first'>First Name:</label></TD>
			<TD><input type='text' name='first' id='first' value='"  . if ($formc == 'Edit'){ echo $_POST['fname']; } . "'/><br/><br/></TD>
		</TR>
        </TABLE>
</form>";

It has something to do with the ‘if’ statement, but not sure what…Please help

You can’t use the if statement inside a variable (nor echo). You can however, use the ternary syntax:

$form="<form action='maintain.php' method='POST'> 
    <TABLE> 
        <TR> 
            <TD><label for='first'>First Name:</label></TD> 
            <TD><input type='text' name='first' id='first' value='"  . ($formc == 'Edit' ? $_POST['fname'] : '') . "'/><br/><br/></TD> 
        </TR> 
        </TABLE> 
</form>";

This should work:

$form="<form action='maintain.php' method='POST'> 
    <TABLE> 
        <TR> 
            <TD><label for='first'>First Name:</label></TD> 
            <TD><input type='text' name='first' id='first' value='";

if ($formc == 'Edit'){ $form .= $_POST['fname']; }

$form .= "'/><br/><br/></TD> 
        </TR> 
        </TABLE> 
</form>";

And it does…

Thank You very much…