This topic is locked

avoiding duplicate scheduling for the same patient

5/1/2019 4:01:22 PM
PHPRunner General questions
brito author

Good afternoon everyone

I have a problem of duplicity in my table when the patient schedules the same date and time the same day, I tried this code but without results, someone has how it gives me a light.
thank you
global $conn;
if ($values["id_cpf"]!=$oldvalues["id_cpf"])

if ($values["dt_atendimento"]!=$oldvalues["dt_atendimento"])

if ($values["turno"]!=$oldvalues["turno"])

{

$strSQLExists = "select from agm_agendamento where id_cpf='".$values["id_cpf"]."'";

$strSQLExists = "select
from agm_agendamento where dt_atendimento='".$values["dt_atendimento"]."'";

$strSQLExists = "select * from agm_agendamento where turno='".$values["turno"]."'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

echo "<center><b><font color=red>Already scheduled date and shift!</font></b></center>";

return false;

}

}

brito author 5/1/2019

Yes, for one column it works, but I'm trying with 3 columns.

M
MikeT 5/2/2019

You need to combine your conditions with AND. In the example you just replace the variable contents, and the last assignment is then used.

(Personally I would also set a constraint at the database level to make sure that there's never a record that matches these conditions.)