php - Avoiding Duplicate Inserts into Database -
i wanna avoid duplicate reservation has same date , spot. how go doing if possible. wanna make sure no 2 customers can make reservation same spot on same day.
// insert data mysql $sql="insert $tbl_name(confirmation, fname, lname, gname, license, floor, spot ) values('$confirm_code', '$fname', '$lname', '$gname', '$license', '$floor', '$spot')"; $result=mysql_query($sql); if (mysql_errno() == 1062)
to prevent duplicate entries use unique index
. defining multiple rows can can control reservations. adding day
column can -
create unique index spot on table_name (spot, day)
this allow 1 reservation per day per spot.
Comments
Post a Comment