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!


$query = "SELECT * FROM deliveredGoods";
$result = mysqli_query($query);

if ($result === false){
<!doctype html>
<meta charset="utf-8">
<title>Update Goods Status</title>
body {
font-family:Cambria, "Hoefler Text", "Liberation Serif", Times, "Times New Roman", "serif";

text-align: center;

border-collapse: collapse;
width: 100%;

tr, th {
border: 1.5px solid #C0C0C0;

<form method='post' action='#'>
<h2>Update Goods Status</h2>

    <th>Goods ID</th>
    <th>Resident ID</th>
    <th>Tracking Number</th>
    <th>Company Name</th>
    <th>Arrival Date</th>
    <th>Date To Collect</th>
        (mark as received)</th> 

    while ($row = mysql_fetch_array($result)) {


    <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>
<input type='submit' name='submit' value='Update'/>

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){
    echo "Status for .$goodsID_c. has been updated.<br>";
    header(location: goodsList.php);


This was marked as solved yet I don't see the solution.

To me Line 90 seems to set the status to Received regardless of the checkbox value.

I think rproffitt is pointing out that you may have a typo where you put a / character before $goodsID_c.

That being said, you have a whole bunch of things wrong here.

Firstly, do not ever not escape user-defined variables passed into MySQL. On line 89, you should be using:

$goodsID_c = mysqli_real_escape_string($mysql_link_identifier, $value);

All that being said, where is your $mysql_link_identifier (the one generated when you connect to MySQL)? You should be passing it in as the first parameter into your mysqli_query() as demonstrated here: https://www.php.net/manual/en/mysqli.query.php

Then, you are using mysqli_query() with mysql_fetch_array() instead of mysqli_fetch_array(). Those are two separate database libraries.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.