I have a problem with some statements that I am using for a CRUD of data with bootstrap, php and html.
I have the following code in which I connect to the DB without including an external library.
<?php
function conectar_bd($query)
{
$DB_SERVER = "localhost";
$DB_USER = "root";
$DB_DATABASE = "dbAdmin";
$DB_PWD = "12345";
$conn=mysqli_connect($DB_SERVER, $DB_USER,$DB_PWD,$DB_DATABASE);
/* check connection */
if (mysqli_connect_errno())
{
printf("Connect failed: %s\n" , mysqli_connect_error());
exit();
}
if ($result=mysqli_query($conn,$query))
echo mysqli_connect_error();
return $result;
}
$sql = "SELECT * FROM administradores ORDER BY Nombre ASC";
$result = mysqli_query($sql); ##LINEA DE ERROR
if(mysqli_num_rows($result) == 0){ ##LINEA DE ERROR
echo '<tr><td colspan="8">No hay datos.</td></tr>';
}else{
$no = 1;
while($row = mysqli_fetch_assoc($result)){
echo '
<tr>
<td>'.$row['idAdmin'].'</td>
<td>'.$row['Nombre'].'</td>
<td>'.$row['Usuario'].'</td>
<td>'.$row['RPE'].'</td>
<td>'.$row['admin_desde'].'</td>
<td>
<a href="edit.php?nik='.$row['idAdmin'].'" title="Editar datos" class="btn btn-primary btn-sm"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span></a>
<a href="consultaadmin.php?aksi=delete&nik='.$row['idAdmin'].'" title="Eliminar" onclick="return confirm(\'Esta seguro de borrar los datos '.$row['idAdmin'].'?\')" class="btn btn-danger btn-sm"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
</td>
</tr>
';
$no++;
}
}
?>
The case is what throws me these two errors when running in the browser and does not show me the consumption.
Warning: mysqli_query () expects at least 2 parameters, 1 given in C: \ xampp \ htdocs \ sistema.tics \ consultadmin.php on line 73
Warning: mysqli_num_rows () expects parameter 1 to be mysqli_result, null given in C: \ xampp \ htdocs \ system.tics \ queryadmin.php on line 74
My table exists and already verify that all the names of both table and rows are fine.