Problem adding products to cart

Asked

Viewed 36 times

0

$id= $_POST['id'];
if(!isset($_SESSION['itens'])){
    $_SESSION['itens'] = array();
}

if(isset($_POST['id'])){
    $id= $_POST['id'];

    if(!isset($_SESSION['itens'][$id])){
        $_SESSION['itens'][$id] = 1;
    }else{
        $_SESSION['itens'][$id] += 1;
    }
}



$consulta = "SELECT * FROM informaoces WHERE id='$id'";
$con = mysqli_query($mysqli,$consulta);
?>

Product name price amount

What’s wrong with this code, When I add other products to the cart, they don’t get added in the same table, now if you keep adding the same products more than once, increases the amount, now if you add another different product; it doesn’t go to the same table

  • I don’t understand. you want to get product information through a request ? What is the purpose of $_POST since the items are in $_SESSIONS ?

  • Is not missing session_start(); not in that code?

  • your code does this http://kithomepage.com/sos/carrinho.php creates an array with the keys being the ids and the values adding +1 to the value of the key already created. Care that is also creating if send null field

  • The session_start() has

  • Atila silva this POST method is to send the id from one page to another

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.