Hello, I want to use the checkbox to update the status of a row in mysql using php. If it is checked and submitted, the status will change from 'collect' to 'received'. I tried many ways but I am not sure where the problem is :( please help!
<?php
include(config.php);
$query = "SELECT * FROM deliveredGoods";
$result = mysqli_query($query);
if ($result === false){
die(mysqli_error());
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Update Goods Status</title>
<style>
body {
font-family:Cambria, "Hoefler Text", "Liberation Serif", Times, "Times New Roman", "serif";
}
h2{
text-align: center;
font-weight:normal;
}
table{
border-collapse: collapse;
width: 100%;
}
tr, th {
border: 1.5px solid #C0C0C0;
padding:5px;
}
</style>
</head>
<body>
<form method='post' action='#'>
<h2>Update Goods Status</h2>
<table>
<tr>
<th>Goods ID</th>
<th>GoodsListID</th>
<th>Resident ID</th>
<th>Tracking Number</th>
<th>Company Name</th>
<th>Arrival Date</th>
<th>Date To Collect</th>
<th>Status</th>
<th>Action
(mark as received)</th>
</tr>
<?php
while ($row = mysql_fetch_array($result)) {
$row_id=$row['goodsID'];
$goodsListID=$row['goodsListID'];
$residentID=$row['residentID'];
$trackingNum=$row['trackingNum'];
$companyName=$row['companyName'];
$arrivalDate=$row['arrivalDate'];
$collectDate=$row['collectDate'];
$status=$row['status'];
echo"<tr>
<td><?php echo $goodsID; ?></td>
<td><?php echo $goodsListID; ?></td>
<td><?php echo $residentID; ?></td>
<td><?php echo $trackingNum; ?></td>
<td><?php echo $companyName; ?></td>
<td><?php echo $arrivalDate; ?></td>
<td><?php echo $collectDate; ?></td>
<td><?php echo $status; ?></td>
<td><?php echo "<input type='checkbox' name='goodsID[]' value='".$row_id."'>"; ?></td>
</tr>";
}
</table>
<input type='submit' name='submit' value='Update'/>
</form>
</body>
</html>
<?php
if(gettype($_POST['goodsID'])=="submit"){
foreach($_POST['goodsID'] as $value){
$goodsID_c = $value;
$query2 = "UPDATE 'deliveredGoods' SET status = 'Received' where goodsID ='"/$goodsID_c."'";
$result2 = mysqli_query($query2);
if ($result2 === false){
die(mysqli_error());
}
echo "Status for .$goodsID_c. has been updated.<br>";
header(location: goodsList.php);
}
}
mysqli_close();
?>