I'm checking the treatment of a web page . I have a series of valid IDs, existing in a table, stored in the variable $ misids; (Returns an array).
I want to check that the user is not "bad" and wants to access a non-existent id of the page.
GetID method:
static public function obtenerIDsCabanas(){
$ejecucion = self::Conexion();
$sql = "SELECT idcabana FROM cabanas";
$registro = $ejecucion->query($sql);
//Creamos un array para almacenar los IDs.
$misids = array();
//Recorremos el array y añadimos en él los ids mediante array_push.
while($idcabana = $registro->fetch()){
//Array asociativo: al array $misids le pasamos $idcabana.
array_push($misids, $idcabana);
}
//Devuelve el array $misids (asociativo).
return $misids;
}
HTML Code:
<?php
$misids = BD::obtenerIDsCabanas();
if(in_array($_REQUEST["idcabana"], $misids)){
echo "SI existe el ID.";
}else{
echo "No existe el ID.";
}
?>
Questions:
1) Why do I always get "Does the ID not exist"?