日期未通过DatePicker输入db

时间:2018-02-24 11:56:19

标签: php mysql

我正在开发一个带日期选择器的约会系统。我的问题是:

  • 当我单击提交按钮时,所选日期不会保留在数据库中,但不会显示错误。
  • 我无法换行提交按钮。
<html>
    <head>
        <link href="jQueryAssets/jquery.ui.core.min.css" rel="stylesheet" type="text/css">
        <link href="jQueryAssets/jquery.ui.theme.min.css" rel="stylesheet" type="text/css">
        <link href="jQueryAssets/jquery.ui.datepicker.min.css" rel="stylesheet" type="text/css">
        <script src="jQueryAssets/jquery-1.11.1.min.js" type="text/javascript">
        </script>
        <script src="jQueryAssets/jquery.ui-1.10.4.datepicker.min.js" type="text/javascript">
        </script>
    </head>
    <body>
        <form method="post" action="">    
            <input  type="text" name="date" id="Datepicker1">    
            <br>
            <br>
            <?php
            include ('db.php');
            $result = $conn->query("select tea_id, username from tea");
            echo "<select required name='tea_id'>";
                while ($row = $result->fetch_assoc())  {
                    //unset($id, $name);
                    $id = $row['tea_id'];
                    $name = $row['username'];
                    echo '<option value="">None</option>';
                    echo '<option  value="'.$id.'">'.$name.'</option>';
                }
            ?>
            <input type="submit" name="submit" value="submit">
        </form>

        <?php
        include ('db.php');
        session_start();

        // Check connection
        if (mysqli_connect_errno()) {
            echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }

        if(isset($_POST['submit']) != "") {
            $date = mysqli_real_escape_string($conn, $_POST['date']);
            $new_date = date('Y-m-d',strtotime($date));
            $tea_id = $_POST['tea_id'];
            {
                $query = mysqli_query(
                    $conn,
                    "INSERT INTO app (date,time,par_id,tea_id) VALUES ('$new_date','".$_SESSION['par_id']."','$tea_id')"
                );
                if($query) {
                    header("location:app.php");
                    echo " Successfully";
                } else {
                    echo " faliure";
                    // die(mysql_error());
                }
            }
        }
        ?>
        <script type="text/javascript">
            $(function() {
                $( "#Datepicker1" ).datepicker();
            });
        </script>
    </body>
</html>

0 个答案:

没有答案