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

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -