0

Im building a table with SQL that show me the sentence that I want, and she have a checkbox array because I want to delete the row that I want

The table look like this

    echo "<table> \n"; 
    while($fila = mysqli_fetch_assoc($resultado))
  {
    $id=$fila['id'];

    echo "<tr><td class='izquierda'>";

    echo "<input type='checkbox' name= 'eliminar[]' value=$id>";

    echo "</td><td>";

    echo $fila['id'];

    echo "</td><td>";

    echo $fila['titulo'];
    echo "</td><td>";

    echo $fila['texto'];
    echo "</td><td>";

    echo $fila['categoria'];
    echo "</td><td>";

    echo $fila['fecha'];
    echo "</td><td class='derecha'>";
    if($fila['imagen']==""){
    echo"<p>-</p>";
    }else{
    echo ("<p><a href='".$fila['imagen']."'/>FOTO</a></p>");
    }
    echo "</td></tr>";
  }

echo "</table></form>";

And I can't catch the value of eliminar[] here:

if(isset($_POST['borrar'])){
        echo "<input href='MEGA_PRUEBA2.php' type='submit' value='recargar' name='recargar'>";
        $eliminarz= $_REQUEST['eliminar'];
        foreach($eliminarz as $idcheck){
            echo"<br>";
            echo "Fila borrada: $idcheck";
            echo "<br>";
            $sentencia2 = "DELETE FROM noticias WHERE id=$idcheck;";
            $resultado2 = mysqli_query($conexion,$sentencia2);
        }

        /*$extra='TODO.php';
        header("location: $extra"); 
        exit;*/
        if(!$resultado2)
                    print("Error: no se pudo realizar la consulta");
    } 

The error is

Notice: Undefined index: eliminar in D:\xampp\htdocs\PHP_EXAMEN\Examen PHP\PRUEBAS\MEGA_PRUEBA2.php on line 61

Thank you :)

0 Answers0