why do I get these php errors?

-1
Notice: Undefined offset: 0 in /Applications/MAMP/htdocs/Homocerveserus/functions/checkout.php on line 14

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /Applications/MAMP/htdocs/Homocerveserus/functions/checkout.php on line 16

Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/Homocerveserus/functions/checkout.php on line 14

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /Applications/MAMP/htdocs/Homocerveserus/functions/checkout.php on line 16

this after using this in a loop

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

                        unset($_SESSION['producto'][$_GET['a']]);
                        $_SESSION["producto"] = array_values($_SESSION["producto"]);

                        unset($_SESSION['cantidad'][$_GET['a']]);

                        $_SESSION["cantidad"] = array_values($_SESSION["cantidad"]);
                }

the complete code is

<?php
session_start();


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'<td></td>';
                echo '<center><td>';
                echo '<center><input type=number name=ja class="las ma" 
                value='.$cab.'></center>';
                echo '</td></center>';
                echo '<td>$'.$fila['Precio'].'</td>';
                echo '<td></td>';
                echo '<td>$'.number_format($total,2).'</td>';
                echo '<td>';
                echo '<input type=hidden value='.$_SESSION['contador'].' 
                class=jk>';
                echo '<a href=functions/checkout.php?a='.$i.'>Borrar</a>';

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


                    $suma += $total;



        }

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

                        unset($_SESSION['producto'][$_GET['a']]);
                        $_SESSION["producto"] = array_values($_SESSION["producto"]);

                        unset($_SESSION['cantidad'][$_GET['a']]);

                        $_SESSION["cantidad"] = array_values($_SESSION["cantidad"]);


                    }

    }

echo '<tr><th colspan="5">Total</th><th colspan="2">$'.number_format($suma,2).'</th></tr>';
mysqli_close($conect);




?>
    
asked by jose moya 18.10.2017 в 01:27
source

2 answers

0

They are errors that you have to fix and they tell you in what line and why is the error.

The first is an index outside the arrangement.

The second is an incorrect call to mysqli_fetch_array

and how are you in a cycle are repeated.

    
answered by 18.10.2017 в 01:36
0

the value of $ _SESSION ['counter'] is different from the number of elements of $ _SESSION ['product'] test with the count function ($ _ SESSION ['product'])

for ($ i = 0; $ i

answered by 19.10.2017 в 01:35