Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php echo within an echo for a checkbox

I'm trying to use checkboxes to display and update records in a MySQL database. I want to change the value of the checkbox based on whether it's checked or unchecked. But I'm getting this error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

Here's the line of code that's throwing the error:

echo"<input type='checkbox' name='PLJan' {if (isset($_POST['PLJan'])) print 'value='checked''} $row->PLJan /> January ";

Is there a better way for me to do this so that saving it will update the database with 'checked' if the box is checked, and a blank if the box is unchecked?

Thanks in advance for the halps.

like image 545
SyrupandSass Avatar asked Jul 08 '26 21:07

SyrupandSass


1 Answers

echo"<input type='checkbox' name='PLJan' {if (isset($_POST['PLJan'])) print 'value='checked''} $row->PLJan /> January ";

should be

echo"<input type='checkbox' name='PLJan'"; 
if (isset($_POST['PLJan'])) { echo " value='checked'"; } 
echo $row->PLJan . "/> January ";
like image 173
Yogesh Suthar Avatar answered Jul 10 '26 10:07

Yogesh Suthar