du21064 2017-07-04 18:55
浏览 22

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");
}
?>
  • 写回答

2条回答 默认 最新

  • dongqie8661 2017-07-04 19:14
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决