I am doing a code of Equipment Rental in Php, in general the code is almost all finished, but in the last step I came across a big problem, I wish the adm, since it is he who makes the reservations, not you can reserve the same equipment twice for the same day and for the same time. So I tried to do the following in Event
include_once'conexao.php';
if(isset($_POST['nomeprof']))$atrNomeprof = $_POST['nomeprof'];
if(isset($_POST['loginprof']))$atrLoginprof = $_POST['loginprof'];
if(isset($_POST['senhaprof']))$atrSenhaProf = $_POST['senhaprof'];
if(isset($_POST['telefoneprof']))$atrTelprof = $_POST['telefoneprof'];
if(isset($_POST['cpfprof']))$atrCPFprof = $_POST['cpfprof'];
if(isset($_POST['disciplinaprof']))$atrDiscprof = $_POST['disciplinaprof'];
if(isset($_POST['emailprof']))$atrEmailprof = $_POST['emailprof'];
if(isset($_POST['nomeequip']))$atrNomeequip = $_POST['nomeequip'];
if(isset($_POST['corequip']))$atrCorequip = $_POST['corequip'];
if(isset($_POST['marcaequip']))$atrMarcaequip = $_POST['marcaequip'];
if(isset($_POST['categoriaequip']))$atrCategoriaequip = $_POST['categoriaequip'];
if(isset($_POST['id_equipamento']))$atride = $_POST['id_equipamento'];
if(isset($_POST['id_professor']))$atridp = $_POST['id_professor'];
if(isset($_POST['data']))$atrdata = $_POST['data'];
if(isset($_POST['hora']))$hora = $_POST['hora'];
if(isset($_POST['hora2']))$hora2 = $_POST['hora2'];
if(isset($_POST['sala']))$sala = $_POST['sala'];
if(isset($_GET['reserva'])){
if($sql == "SELECT * from reservas where id_equipamento= '" . $atride . "' AND horario='".$hora."' AND dt_reserva='".$atrdata."' "){
echo $sql;
echo "<script> alert('Você ja Reservou esse equipamento para esse Dia e Horario') </script>";
}
else{
$sql = sprintf("INSERT INTO 'reservas' SET 'id_equipamento' = \"%d\", 'id_adm' = \"%d\", 'horario' = \"%s\", 'dt_reserva' = \"%s\", 'id_professor' = \"%d\";",
$atride,
$userId,
$hora,
$atrdata,
$atridp);
// echo $sql;
mysql_query($sql,$con);
echo"<script> alert('Equipamento Reservado com sucesso')</script>";
}
}
But when I try to reserve equipment that is already reserved in the bank, the code simply ignores the second if
as if it were not even there.
% ignored% is
if($sql == "SELECT * from reservas where id_equipamento= '" . $atride . "' AND horario='".$hora."' AND dt_reserva='".$atrdata."' "){
echo $sql;
echo "<script> alert('Você ja Reservou esse equipamento para esse Dia e Horario') </script>";}
I have analyzed this If several times and tried to make changes such as instead of if
put only ==
but then when I do this all future reservations, even those that are not then in the database will automatically enter =