I would like to know in what way I can know which data is not met when making my query to the database from PHP
.
I mean I want to know in what way I can condition my code to know which parameter of the WHERE
instruction is being violated.
It is for when someone incorrectly enters the data within a form, it is known if it is because there is not one of the parameters entered.
<?php
$con=mysqli_connect('127.0.0.1','root','','freatico') or die ('Error en la conexion');
$sql="SELECT Nivel FROM medicion WHERE idp='$_POST[pun]'and Nivel>=1.20";
$resultado=mysqli_query($con,$sql) or die ('Error en el query database');
//Valida que la consulta esté bien hecha
if( $resultado ){
//Ahora valida que la consuta haya traido registros
if( mysqli_num_rows( $resultado ) > 0){
//Mientras mysqli_fetch_array traiga algo, lo agregamos a una variable temporal
while($fila = mysqli_fetch_array( $resultado ) ){
//Ahora $fila tiene la primera fila de la consulta, pongamos que tienes
//un campo en tu DB llamado NOMBRE, así accederías
echo $fila['Nivel'];
}
}
else {
echo 'NO EXISTE EL PUNTO/NO HAY PUNTOS CRITICOS';
}
//Recuerda liberar la memoria del resultado,
mysqli_free_result( $resultado );
//Si ya no ocupas la conexión, cierrala
mysqli_close( $con );
}
?>