Trying to access array offset on value of type null in Table.php, on line 115, 117, 118, and 119

  html, mysql, php

trying to insert/update data inside this table. I have been messing with the input tags for hours and I dont see anything wrong and is not getting information from any arrays. Are my tags wrong or is my php code wrong somewhere?

Please let me know if you need any other information.

Here is my table

        <?php
            $conn = mysqli_connect("localhost:3306", "root", "", "test");
            $sql = "SELECT idNumber, itemName, itemQuantity, itemLocation, itemDept, itemIndex FROM inventorydatabase";
            $result = $conn->query($sql);
            while($res = mysqli_fetch_array($result))
            {
                $itemid = $res['idNumber'];
                $itemname = $res['itemName'];
                $itemquantity = $res['itemQuantity'];
                $itemlocation = $res['itemLocation'];
                $itemdept = $res['itemDept'];
                $itemindex = $res['itemIndex'];
            }
        ?>


        <form name="reg-frm" action="Table.php" method="POST">
            <table class="tableCSS">
                <tbody>
                    <tr>
                        <td><input id="name" type="number" name="itemid" value=""/></td>

**LINE 115**                <td><input id="name2" type="text" name="itemname" value="<?php echo $row['itemName']; ?>"/></td>

                        <td><input id="name3" type="number" name="itemquantity" value="<?php echo $row['itemQuantity']; ?>"/></td>

**LINE 117**                <td><input id="name4" type="text" name="itemlocation" value="<?php echo $row['itemLocation']; ?>"/></td>

**LINE 118**                <td><input id="phone" type="text" name="itemdep" value="<?php echo $row['itemDept']; ?>"/></td>

**LINE 119**                <td><input id="name5" type="text" name="itemindex" value="<?php echo $row['itemIndex']; ?>" /></td>
                    </tr>
                </tbody>
            </table></br>
            <div style="text-align: center;">
                <input type="submit" value="SAVE" name="save" class="submit-btn"/>
            </div>
        </form>

        <?php
        if(isset($_POST['save'])){
            
            $itemid =$_POST['itemid'];
            $itemname =$_POST['itemname'];
            $itemquantity =$_POST['itemquantity'];
            $itemlocation =$_POST['itemlocation'];
            $itemdept =$_POST['itemdep'];
            $itemindex =$_POST['itemindex'];
            
            $sql = "UPDATE inventorydatabase SET itemName='$itemname', itemQuantity='$itemquantity', itemLocation=$itemlocation', itemDept='$itemdept', itemIndex='$itemindex' WHERE idNumber='$itemid'";
        }
        ?>

here is my $row table

Source: Ask PHP

LEAVE A COMMENT