为什么我不能显示错误信息?

时间:2017-01-26 13:33:33

标签: php html validation

当数据库中的username == username和数据库中的date == date时,它应该回显错误消息,但它显示成功。我尝试使用“=”,但即使数据被认为是正确的,结果仍会回显错误消息。请帮忙。

这些是我的代码:

    if(!empty($_POST['username'])){

        $username=$_POST['username'];
        }
        else
        {
        $username=null;
        $usererr = "";
        }

     if(!empty($_POST['datepicker'])){
       $date = date('y-m-d', strtotime($_POST['datepicker']));
       }
        else
        {
        $date=null;
        $dateerr = "";
        }

        $mysqli = new mysqli("", "", "", "");

            $stmt = $mysqli->prepare("SELECT username, date FROM booking WHERE username='$username' and date ='$date'");

            $stmt->bind_param("ss", $username, $date); 

            $stmt->execute();

            $stmt->bind_result($cusername, $cdate);
            $stmt->fetch();

        if($cusername == $username && $cdate == $date){
            echo"You have already book this day. Please select another day";
        }
        else{
            echo"Success";
            $chdate = $date;
        }
         if($username && $date && $chdate){

        session_start();

        $mysqli = new mysqli("", "", "", "");

        stmt = $mysqli->prepare("INSERT INTO booking (, , , , )
                            VALUES ('',''");

        $result = $stmt->execute();

        }
        $stmt->close();
        $mysqli->close();

1 个答案:

答案 0 :(得分:0)

检查这个

$date = date('y-m-d', strtotime($_POST['datepicker'])); 

这将使2017年的年份恢复为“17”,请尝试这样

 $date = date('Y-m-d', strtotime($_POST['datepicker']));