我想顯示此消息「已預訂 - 請選擇其他日期」如果兩個客戶選擇相同的產品(pg_no)和日期(Date) 。唯一約束PHP&MYSQL - 如何顯示「已預訂請選擇其他日期」信息
<?php
//connecting string
include("dbconnect.php");
//assigning
$name=$_REQUEST['Name'];
$tele=$_REQUEST['Tele'];
$city=$_REQUEST['City'];
// UNIQUE CONSTRAINT
$pg_no=$_REQUEST['pg_no']; //product
$date=$_REQUEST['Date']; //date
//checking if pg_no and Date are same
$check = mysqli_query($db_connect,"SELECT * FROM lstclient WHERE pg_no='{$pg_no}', Date='{$date}'");
{
echo "Already booked please select another date<br/>";
}
//if not the insert data
else
{
$query = mysqli_query($db_connect,"INSERT INTO lstclient(pg_no,Name,Tele,City,Date) VALUES('$pg_no','$name','$tele','$city','$date')") or die(mysql_error());
}
// link closing
mysqli_close($db_connect);
// messaging
if($query)
{
header("location:index.php?note=failed");
}
else
{
header("location:index.php?note=success");
}
?>
我應該在HTML頁面添加什麼 –
請至少發佈有效的代碼 - 'INSERTINTOlstclient'不正確。 –
INSERT INTO lstclient –