Ayaz Ayaz - 1 month ago 8x
MySQL Question

Multiple checkbox validation in php-mysql

I have 6 checkbox, If all of them are checked it goes to the next step. But it is giving error :

Parse error: syntax error, unexpected '&&' (T_BOOLEAN_AND) in C:\xampp\htdocs\practice_login\release_cause_report2.php on line 143

<?php if($_POST['Date'] == 'Date') &&
if($_POST['ASR'] == 'ASR') &&
if($_POST['ACD'] == 'ACD') &&
if($_POST['CER'] == 'CER') &&
if($_POST['TQI'] == 'TQI') &&
if($_POST['min'] == 'min')

<li><label>Date </label><input type="checkbox" id="Date" name="Date"></li>
<li><label>ASR </label><input type="checkbox" id="ASR" name="ASR"></li>
<li><label>ACD </label><input type="checkbox" id="ACD" name="ACD"></li>
<li><label>CER </label><input type="checkbox" id="CER" name="CER"></li>
<li><label>TQI </label><input type="checkbox" id="TQI" name="TQI"></li>
<li><label>TQI </label><input type="checkbox" id="min" name="min"></li>
<li><input type="submit" name="submit" value="Submit" /></li>


If you want to combine if-statements you can add the statements inside the brackets of the if. It is not possible to write an if inside if.

Write this instead:

if(($_POST['Date'] == 'Date') &&
($_POST['ASR'] == 'ASR') &&
($_POST['ACD'] == 'ACD') &&
($_POST['CER'] == 'CER') &&
($_POST['TQI'] == 'TQI') &&
($_POST['min'] == 'min'))

Or shorter:

<?php if($_POST['Date']=='Date'&&$_POST['ASR']=='ASR'&&$_POST['ACD']=='ACD'&&$_POST['CER']=='CER'&&$_POST['TQI']=='TQI'&&$_POST['min']=='min'){?>

And maybe you have to add isset to check if the $_POST[] query is set:

<?php if(isset($_POST['Date'])&&isset($_POST['ASR'])&&isset($_POST['ACD'])&&isset($_POST['CER'])&&isset($_POST['TQI'])&&isset($_POST['min'])&&$_POST['Date']=='Date'&&$_POST['ASR']=='ASR'&&$_POST['ACD']=='ACD'&&$_POST['CER']=='CER'&&$_POST['TQI']=='TQI'&&$_POST['min']=='min'){?>