Mysql继续删除错误的表行

User should be able to delete a specific row but the programs keep deleting first row. I have found an answer here Tried it did not work. I wonder what I'm doing wrong.

cart.php

 <form id='updateCartForm' action="update_cart.php" method="get">
             <input name="cart_item_name" type = "hidden"  id ="cart_item_name" value='<?=$product['prod_name'];?>'>
 <input name="cart_item_id" type = "hidden"  id ="cart_item_id" value='<?=$product['id'];?>'>
 </form>

update_cart.php

<?php
require_once "core/db.php"

//get data from form
$cart_item_name = $_GET['cart_item_name'];
$cart_item_id = $_GET['cart_item_id'];

//execute query
$sql = "DELETE FROM cart WHERE id =" .$cart_item_id;  
$db->query($sql);

//flash success message
$domain =($_SERVER['HTTP_HOST'] != 'localhost')?'.'.$_SERVER['HTTP_HOST']:false;
$_SESSION['success_flash'] = $cart_item_name. ' was deleted from your cart.'; 

Delete query will delete all rows if no WHERE clause is there, otherwise it delete the rows matching with the WHERE caluse.

If it is not working as expected than put a check on variable that contains the id like:

echo $cart_item_id;
exit;

and see what it contains.

Is the design right?
In your previous question also, I commented whether you have your design right. Using a product id as a cart item id as you are doing ehre does not make sense.

<form id='updateCartForm' action="update_cart.php" method="get">
             <input name="cart_item_name" type = "hidden"  id ="cart_item_name" value='<?=$product['prod_name'];?>'>
 <input name="cart_item_id" type = "hidden"  id ="cart_item_id" value='<?=$product['id'];?>'>
 </form>

Deleting using this cart_item_id would actually mean deleting all items in the cart from all users where the product is is $product['id']

That brings me to the second point. Why do you have both the product name and product id in the form? Only the product id is needed. Getting onto the delete.

Conclusion, you have the wrong table design or wrong query design.

What's the first row?

the programs keep deleting first row.

There is no order by in your query. SO there is no such thing here as a first row. What's actually happening is probably what I have described in my first paragraph.

SQL injection
Now for a major security issue.

$sql = "DELETE FROM cart WHERE id =" .$cart_item_id;  
$db->query($sql);

This is a horrible way to do a query. You will some day find that not just one row but the whole database has been deleted. Read up on PDO prepared statements.

Decided to go with the easier way using href.

cart.php

<a href="update_cart.php?productcartid=<?=$product['id'];?>">&times</a>

update_cart.php

<?php
ob_start();
require_once 'core/db.php';

//delete from cart

           $productcartid =$_REQUEST['productcartid'];

           // sending query
           $del = "DELETE FROM cart WHERE id='$productcartid'";
           $db->query($del);
           header("Location: cart.php");