keep the amount after refresh

0

So I add the product:

 if (isset($_GET['acao'])) {
    if ($_GET['acao'] == 'add') {
    $id = intval($_GET['id']);
  if (!empty($_SESSION['shop'][$id]))
    //if (!isset($_SESSION['shop'][$id]))
        $_SESSION['shop'][$id] = 1;
    } else {
        $_SESSION['shop'][$id] += 1;
    }  e aqui o input :   echo'<td><input rel="'.$linha['id'].'" type="number" step="1" min="1" style="width:50px; font-family: Tahoma; font-size: 20px;" name="prod[' . $id . ']" value="' . $qtd . '"></td>';

I'd like to know how I can keep the amount after a refresh. For example: if I choose 2 products, when I refresh the page, I return the quantity of 1 product.

    
asked by anonymous 04.02.2016 / 14:29

1 answer

0

Just simple logic error

Correction hint

 if (
     isset($_GET['acao'])
     && $_GET['acao'] == 'add'
 ) {
     $id = intval($_GET['id']);
     if (
         isset($_SESSION['shop'][$id])
         || empty($_SESSION['shop'][$id])
     ) {
         $_SESSION['shop'][$id] = 1;
     } else {
         $_SESSION['shop'][$id] += 1;
     }
 }

Note: Be aware that in a refresh / reload of the page, values will be constantly increased.

    
04.02.2016 / 16:23