PHP和MYSQL - 如何显示“已经预订请选择另一个日期”消息[关闭]

I want to display this message "Already booked - please select another date" If two clients select the same product (pg_no)and date (Date). UNIQUE CONSTRAINT

<?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");
}
?>

To view the message on your HTML page, based on the code you have provided, you just need to set a $_GET var:

<?php
if (isset($_GET['note']))
{
    if($_GET['note'] == 'failed';)
    {
        $note = "Those dates have already been booked.";
    }
    else if($_GET['note'] == 'success')
    {
        $note = "You have been booked!";
    }
}
else
{
    $note = "";
}
?>

<div class="message">
    <p class="alert">
        <?php
            if ($note != "")
            {
                echo $note;
            }
        ?>
    </p>
</div>

That would check for a note parameter in your url and set it to $note then output it in your HTML.

You don't need to add anything to the database, you can save the request and log it so you can view which dates are the most popular.

You have two simple options here.

Option 1 - Assign the message to a variable

Instead of echoing your error message, store it in a variable which has a default value (for example, "Success"). Then, where you do the final header() part of your code, return this variable as note:

$my_str = "Already booked please select another date<br/>";

...

header("location:index.php?note=$my_str");

Then on the HTML side, you just need to print the value of $_GET['note'].

Option 2 - See Samuel Fonseca's answer

He beat me to it!