(!) Warning: mysqli_fetch_array () expects parameter 1 to be mysqli_result, boolean given in C: \ wamp \ www \ final p4 \ deletion_table.php on line 20

1

hello I have a problem I want to select in a data case a column by measure of a form and the selected one print it

introducir el código aquí<html><head>
<link rel="stylesheet" href="CSS/principal.css" type="text/css">
</head>
<body>
<form action="tabla_borrar.php" method="POST">
<p>Buscar Para borrar Por:</p>
<p>nombre <input type="radio" name="Buscar" value="nombre"/></p>
<p>precio<input type="radio" name="Buscar" value ="precio"/></p>
<p>id<input type="radio" name="Buscar" value="id"/></p>
<input type="reset" value="Borrar"> <input type="submit"><br><br><br>
<a href="index.php">DEVOLVER A EL FORMULARIO </a>
</form>
</body>
</html>

code to print the table

<link rel="stylesheet" href="CSS/principal.css" type="text/css">
<?php
$link = mysqli_connect("localhost","root","");
mysqli_select_db($link,"db1") or die ("Error al conectar a la base de         
Datos");
$buscar = $_POST['Buscar'];
$query=mysqli_query($link, "SELECT ".$buscar.",codigo FROM tal1 ");
?>
<html>
<body>
<h1>Eliminacion de Productos</h1>
<form method="POST" >
<table border="1" bgcolor="gray">
<tr>
<th colspan="2">Eliminar</th>




</tr>
<?php
while($arreglo=mysqli_fetch_array($query)){
?>
<tr>
<th><input type="checkbox" name="casilla[]" value="<?php echo                  
$arreglo['codigo'] ; ?>"></th>
<th><?php echo $arreglo[$buscar] ;?></th>
</tr>
<?php
}
?>
</table>
<input type="submit" value="Eliminar">
</form>

<a href="index.php">DEVOLVER A EL FORMULARIO </a>
</body>
</table>
    
asked by Tomas Hernandez 04.11.2018 в 17:34
source

1 answer

0
  • the query should not be like this:
  • the error that you send is because the query is not returning anything!
  • $link = mysqli_connect("localhost","root","");
    mysqli_select_db($link,"db1") or die ("Error al conectar a la base de         
    Datos");
    // previene sql injection
    $buscar = filter_var($_POST['Buscar'], FILTER_SANITIZE_STRING);
    
        // como lo tienes esta mal jamas deberias hacerlo
        // suponiendo que tu campo se llama busca seria asi:
    
        $query=mysqli_query($link, "SELECT busca, codigo FROM tal1 where buscar='".$buscar."' ");
        if(!$query){ die("no hubo resultados sorry");}
        ?>
        <html>
        <body>
        <h1>Eliminacion de Productos</h1>
        <form method="POST" >
        <table border="1" bgcolor="gray">
        <tr>
        <th colspan="2">Eliminar</th>
    
    
    
    
        </tr>
        <?php
        while($arreglo=mysqli_fetch_array($query)){
        ?>
        <tr>
        <th><input type="checkbox" name="casilla[]" value="<?php echo                  
        $arreglo['codigo'] ; ?>"></th>
        <th><?php echo $arreglo[$buscar] ;?></th>
        </tr>
        <?php
        }
        ?>
        </table>
        <input type="submit" value="Eliminar">
        </form>
    
        <a href="index.php">DEVOLVER A EL FORMULARIO </a>
        </body>
        </table>
    
        
    answered by 04.11.2018 в 20:25