Updated 2022-05-22 0
Viewed 12 times

I am new to PHP and I need some help. I am having an issue where, I can update the data successfully BUT the changes will not reflect within phpMyAdmin.

I am trying to get it to where a user will search for an item, and if they want to update that item (add information/change info, etc) they can click on a link. I have details.php set up like so:

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

        table, th, td {
            border:1px solid black;

            text-align: center;

            text-align: center;


    <h1 class="ssinv">Sulley Sells Update Items</h>

    <table class="invtable" style="width:100%">
        <th>Product ID</th>

$servername = "localhost";
$username = "u***_inventory";
$password = "***";
$db = "u***_products";

$conn = new mysqli($servername, $username, $password, $db);

if ($conn->connect_error){
    die("Connection failed: ". $conn->connect_error);

$id = $_GET['id'];
$id = mysqli_real_escape_string($conn,$id);
$sql = 'SELECT * FROM inventory WHERE product_id = "' .$id. '" ';
$result = mysqli_query($conn,$sql);

while($row = mysqli_fetch_assoc($result)) {
   $id = $row['product_id'];
   $product = $row['product']; 
   $description = $row['description'];
   $location = $row['location'];
   echo "<tr><td>$id</td>";
   echo "<td>$product</td>";
   echo "<td>$description</td>";
   echo "<td>$location</td></tr>";


    <form action="/SulleySells/scripts/updateitem.php" method="post">

    <script type="text/javascript">
        function ShowHideDiv(listed) {
            var updatel = document.getElementById("updatel");
            updatel.style.display = listed.checked ? "block" : "none";
        function ShowHideDiv2(sold) {
            var updates = document.getElementById("updates");
            updates.style.display = sold.checked ? "block" : "none";
    <label for="listed">
    <input type="checkbox" id="listed" onclick="ShowHideDiv(this)" />
    <label for="sold">
    <input type="checkbox" id="sold" onclick="ShowHideDiv2(this)" />
    <hr />
    <div id="updatel" style="display: none">
        <h3>Update Listing Details:</h3>
        <label for="list_date">Listed Date:</label>
        <input type="date" id="updateltext" name="list_date" />
        <label for="list_price">Listed Price:</label>
        <input type="text" id="updateltext"  name="list_price"/>
        <button>Update Listing Info</button>
     <div id="updates" style="display: none">
         <h3>Update Sale Details:</h3>
        <label for="sold_date">Sold Date:</label>
        <input type="date" id="updatestext" name="sold_date"/>
        <label for="sold_price">Sold Price:</label>
        <input type="text" id="updatestext" name="sold_price"/>
        <label for="ship_date">Ship Date:</label>
        <input type="date" id="updatestext" name="ship_date" />
        <label for="ship_cost">Ship Cost:</label>
        <input type="text" id="updatestext" name="ship_cost"/>
        <a>Update Sold Info</button>

The issue I am having is with my updateitem.php. I can update successfully but I am having an issue and I do not know how to select the ID from the "Update" link that is produced in details.php. Updateitem.php is shown below:

$id = isset($_GET['id']) ? $_GET['id'] : 'product_id';
$listdate = $_POST["list_date"];
$listprice = $_POST["list_price"];
$solddate = $_POST["sold_date"];
$soldprice = $_POST["sold_price"];
$shipdate = $_POST["ship_date"];
$shipcost = $_POST["ship_cost"];

$servername = "localhost";
$username = "u***_inventory";
$password = "***";
$db = "u***_products";

$conn = new mysqli($servername, $username, $password, $db);

if ($conn->connect_error){
    die("Connection failed: ". $conn->connect_error);

$sqlquery = "UPDATE inventory SET list_date = '$listdate', list_price = '$listprice', sold_date = '$solddate', sold_price = '$soldprice', ship_date = '$shipdate', ship_cost= '$shipcost' WHERE product_id = '$id' ";

if($conn->query($sqlquery) === TRUE){
    echo "Record Saved.";
} else {
    echo "Error!";


I need to be able to assign an ID to the update link so that I can get my updateitem.php file to make the changes in the database.

🔴 No definitive solution yet