0
I’m making a code for 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 Adm, because it is he who makes the reservations, cannot reserve the same equipment twice for the same day and time. So I tried to do the following at the 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 book a piece of equipment that is already reserved in the bank the code simply ignores the second if
like he wasn’t even there.
the if
ignored is this
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 as instead of ==
put only one =
but then when I do this all future reservations, even those not then in the bank will automatically enter the if
That doesn’t make any sense:
if($sql == "SELECT * from reservas where id_equipamento= '....
- You are not testing the query result (you did not even run it).– Bacco
So what would be the best solution for me to test and run the Query ?
– user77891
mysql_query($sql,$con); and test if it has brought results. But this is not the right way. has to for a single input taking the desired columns, try to insert and check if duplicate key error has occurred.
– Bacco
the solution is here: https://answall.com/questions/23014/70
– Bacco