Help with an error in php I explain what happens below

0

in this command code with js the product id by a button and the amount

  echo '<p class="price">$'.$precio.'</p>';
   echo '<p class="buttons">';
   echo '<a href="detail.html" class="btn btn-default">Ver 
    Detalle</a>';
      //cantidad                                             
  echo '<input type="number" name="ja" value="0" id="jaa" class="la 
   ma">';
       //bootn que manda el id del producto                                   
  echo '<button value="'.$id.'" class="boton_compra">Añadir 
  Carrito</button>';

in the js I have

 $(document).ready(inicio)

  function inicio(){

  $(".boton_compra").click(anade);
$("#carrito").load("functions/poncarrito.php");
$("#carrito2").load("functions/checkout.php");


}


 function anade(){

var fila = $(this).parents("p");

if(fila.find(".ma").val() >0){

$("#carrito").load("functions/poncarrito.php?p="+$(this).val());
$("#carrito").load("functions/poncarrito.php?
 c="+fila.find(".ma").val());

$("#carrito2").load("functions/checkout.php?p="+$(this).val());
$("#carrito2").load("functions/checkout.phpc="+fila.find(".ma").val());

}else{
alert("Ingrese cantidad");
}


}

which I send to the php to perform the operation

<?php
session_start();

if(isset($_GET['p'])){
  $_SESSION['producto'][$_SESSION['contador']] = $_GET['p']; 
  $_SESSION['contador']++;


 }

if (isset($_GET['c'])){
$_SESSION['cantidad'][$_SESSION['contador']] = $_GET['c'];
 }

include '../conexion/server.php';

 $suma = 0;
 for ($i=0; $i < $_SESSION['contador']; ++$i){
//echo "producto:".$_SESSION['producto'][$i]."-".$_GET['c'][$i]."<br>";

    $query = mysqli_query($conect,'SELECT * FROM Productos WHERE 
    id='.$_SESSION['producto'][$i].'');

    while ($fila = mysqli_fetch_array($query)) {


        $cab = $_SESSION['cantidad'][$i+1];
        $total = $fila['Precio']*$cab;

            echo '<tr>';
            echo '<td>'.$fila['Nombre'].'</td>';
            echo '<center><td>';

            echo '<center><input type=number name=ja class="la" 
      //aqui es el error
    value='.$cab.'></center>';
            echo '</td></center>';

            echo '<td>'.number_format($total,2).'</td>';
            echo '<td>';
            //echo $i;

            //echo '<input type=hidden name=ya class=na value='.$i.'>';
            //echo '<form action="functions/poncarrito.php" 
       method="post">';
            //echo '<button type=submit name="ka" 
   class="boton_borrar">borrar</button>';
            //echo '</form>';
            echo '<a href=functions/poncarrito.php?a='.$i.'>X</a>';

            echo '</td>';
            echo '</tr>';


                $suma += $total;


    }

}

if(isset($_GET['a'])){

    echo '<script>window.location="../tienda.php";</script>';

    unset($_SESSION['producto'][$_GET['a']]);
    unset($_SESSION['cantidad'][$_GET['a']+1]);
    $_SESSION['producto'] = array_values($_SESSION['producto']);
    $_SESSION['cantidad'] = array_values($_SESSION['cantidad']);
    $_SESSION['contador']--;

 }

 echo '<tr><td></td><td>Subtotal</td>
 <td>$'.number_format($suma,2).'</td></tr>';
 mysqli_close($conect);
 ?>

The thing is that when I enter the amount at times it does not send the value of the amount and when I only put the variable $ _SESSION ['amount'] = get ['c'] and I print that in the table gives me error and as I put it now (in the php above) if it prints that value but every2 does not print the value and additional how can I validate so that when I click on a button with the same value instead If the loop keeps running, add the amount and do not increase a product to the list.

I put $ cab = $ _SESSION ['amount'] [$ i + 1]; because if I leave him alone with $ i he gives me an error of the offset if I pass him as a variable without an index gives me an error I WOULD THANK YOU VERY MUCH IF YOU CAN HELP ME

    
asked by jose moya 20.10.2017 в 21:22
source

0 answers