I need to be able to modify a record using a table, but it happens that when I want to execute the action of the button, it sends me an error.
I had previously done a test with a table of 15 records or so and it did work, but when I tried to do this one that has more than a thousand records it showed me the error.
This is my table:
<div class="container">
<table class="table display table-striped table-responsive">
<thead style="color: #5acbf5">
<tr>
<th>Sinatura</th>
<th>Titulo</th>
<th>Autor</th>
<th><a href="nuevo1.php"><button type="button" class="btn btn-info">Nuevo</button></a></th>
</tr>
</thead>
<tbody>
<?php
include "conexion.php";
$sentencia = "SELECT * FROM books";
$resultado = $conexion->query($sentencia) or die (mysqli_error($conexion));
while($fila = $resultado->fetch_assoc()){
echo "<tr style='color: #7dce30'>";
echo "<td>"; echo $fila['Sinatura']; echo "</td>";
echo "<td>"; echo $fila['Titulo']; echo "</td>";
echo "<td>"; echo $fila['Autor1']; echo "</td>";
echo "<td><a href='modificar1.php?no=".$fila['ID']."'> <button type='button' class= 'btn btn-success'>Modificar</button></a></td>";
echo "<td><a href='eliminar.php?no=".$fila['ID']."'> <button type='button' class= 'btn btn-danger'>Eliminar</button></a></td>";
echo "</tr>";
}
?>
</tbody>
I get the following error:
Fatal error: Uncaught Error: Call to a member function fetch_assoc () on boolean in C: \ xampp \ htdocs \ scripts \ operations \ modify1.php: 9 Stack trace: # 0 C: \ xampp \ htdocs \ scripts \ operations \ modify1.php (3): ProductInquiry ('1') # 1 {main} thrown in C: \ xampp \ htdocs \ scripts \ operations \ modify1.php on line 9
And in that part I have done:
<?php
//modificar1.php
$consulta = ConsultaProducto($_GET['no']);
function ConsultaProducto($no_prod){
include 'conexion.php';
$sentencia = "SELECT * FROM books WHERE no='".$no_prod."' ";
$resultado = $conexion->query($sentencia);
$fila = $resultado->fetch_assoc(); //Aquí es donde me marca el error
return[
$fila['Sinatura'],
$fila['Titulo'],
$fila['Autor1']
];
}
Therefore, I do not know what to do ... I tried with array
but it did not work either.
This part is divided into modificar1
and modificar2
, where the other is:
<?php //modificar2.php
ModificarProducto($_POST['no'], $_POST['Sinatura'], $_POST['Titulo'], $_POST['Autor1']);
function ModificarProducto($no, $id_prod, $nom, $descrip){
include 'conexion.php';
$sentencia="UPDATE books SET Sinatura='".$id_prod."', Titulo='".$nom."', Autor1='".$descrip."' WHERE no='".$no."' ";
$conexion->query($sentencia) or die ("ERROR al actualizar datos");
}