Need help! :)
I want to insert the correct value for checkbox for each row. See this Picture 1, but when I try to hit submit button, the data repeats depending on the last checkbox that I've checked. See this Picture 2. Here are my codes for reference. Thank you in advance! I'm looking forward to hear you as soon as possible.
<?php
include 'database.php';
session_start();
if(isset($_POST['save']))
{
$plant_id = $_POST['plant_id'];
$workplace_id = $_POST['workplace_id'];
$checklistSQL = $connect->query("SELECT * FROM checklist WHERE plant_id =
'$plant_id' AND workplace_id = '$workplace_id' ");
while($cdata = $checklistSQL->fetch_assoc())
{
$checklist = $cdata['checklist'];
$answer = $_POST['answer'];
$remarks = $_POST['remarks'];
$insertSQL = $connect->query("INSERT INTO report(checklist, answer, remarks) VALUES ('$checklist', '$answer', '$remarks') ");
}
}
?>
<?php
$checklistSQL = $connect->query("SELECT * FROM checklist WHERE plant_id = '$plant_id' AND workplace_id = '$workplace_id' ");
while($cdata = $checklistSQL->fetch_assoc())
{
$checklist = $cdata['checklist'];
?>
<tr>
<td><?php echo $checklist ?></td>
<td><input type="checkbox" name="answer" value="yes" <?php if(isset ($_POST['yes'])){ echo "Yes"; } ?> /></td>
<td><input type="checkbox" name="answer" value="no" <?php if(isset($_POST['no'])) { echo "No"; } ?> /></td>
<td><input type="checkbox" name="answer" value="n/a" <?php if(isset($_POST['n/a'])) { echo "N/A"; } ?> /></td>
<td><input type="text" name="remarks" class="remarks" placeholder"Remarks"/></td>
<?php
}
?>
</tr>
Aucun commentaire:
Enregistrer un commentaire