-2

I wanna avoid a duplicate reservation that has the same Date and Spot. How would I go about doing this if possible. I wanna make sure no two customers can make a reservation for the same Spot on the same Day.

   // Insert data into mysql
    $sql="INSERT INTO $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)
4

1 回答 1

0

为防止重复条目,请使用UNIQUE INDEX. 通过用多行定义它,您可以轻松控制您的预订。因此,通过添加一Day列,您可以执行 -

CREATE UNIQUE INDEX spot ON table_name (Spot, Day)

这将只允许每个地点每天进行 1 次预订。

于 2013-07-11T02:57:24.587 回答