0

I am getting an error when updating a product in the cart.

Notice: Array to string conversion in C:\xampp\htdocs\ecommerce\cart.php on line 109

Line 109 refers to this line in the code below to input that contains this['qty'] the input type of quantity.

<?php

function updatecart(){

global $con;

$ip=getIp(); 

if(isset($_POST['update_cart'])){

foreach($_POST['remove'] as $remove_id){

$delete_product="delete from cart where p_id='$remove_id' AND ip_add='$ip'";

$run_delete = mysqli_query($con, $delete_product);

if($run_delete){   
  echo "<script>window.open('cart.php','_self')</script>";
    }
}

}

} if(isset($_POST['continue'])){

echo "<script>window.open('index.php','_self')</script>";

}
Jonny C
  • 1,943
  • 3
  • 20
  • 36

1 Answers1

0

$remove_id is returning an array not a string.

You would need to var_dump($remove_id) to see what format the data is being returned.

From there you would be able to identify the key of the inner array.

So you would be passing $remove_id[key].

You should consider securing your query also as mentioned in the comments its vulnerable to SQL injection. Check out this How can I prevent SQL injection in PHP?

Community
  • 1
  • 1
Jonny C
  • 1,943
  • 3
  • 20
  • 36