Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有jQuery日期选择器的PHP表单_Php_Jquery_Mysql_Model View Controller_Datepicker - Fatal编程技术网

带有jQuery日期选择器的PHP表单

带有jQuery日期选择器的PHP表单,php,jquery,mysql,model-view-controller,datepicker,Php,Jquery,Mysql,Model View Controller,Datepicker,我正在用MySQL构建一个MVC PHP web应用程序。我正在使用表单从用户处收集信息。当日期信息以正确的顺序输入时,日期输入就起作用了,但我希望这对我不太懂技术的同事来说更方便(上帝保佑他们) 这是我在'index.php'中的表单: if($action == 'add_order'){ $distributor_id = filter_input(INPUT_POST, 'distributor_id', FILTER_VALIDATE_INT); $code = fil

我正在用MySQL构建一个MVC PHP web应用程序。我正在使用表单从用户处收集信息。当日期信息以正确的顺序输入时,日期输入就起作用了,但我希望这对我不太懂技术的同事来说更方便(上帝保佑他们)

这是我在'index.php'中的表单:

    if($action == 'add_order'){
  $distributor_id = filter_input(INPUT_POST, 'distributor_id', FILTER_VALIDATE_INT);
  $code = filter_input(INPUT_POST, 'code');
  $name = filter_input(INPUT_POST, 'name');
  $date = filter_input(INPUT_POST, 'date');
  if($distributor_id == NULL || $distributor_id == FALSE || $code == NULL ||
      $name == NULL || $date ==NULL){
        $error = "Invalid order data: Something is wrong";
        include('../errors/error.php');
      }else{
        add_order($distributor_id, $code, $name, $date);
        header("Location: .?distributor_id=$distributor_id");
      }
}
?>
这是我在“order_add.php”中的表格:

    <h1>Add order</h1>
  <form action="index.php" method="post" id="add_order_form">
    <input type="hidden" name="action" value="add_order">
    <label>distributor:</label>
    <select name="distributor_id">
      <?php foreach ($distributors as $distributor) : ?>
        <option value="<?php echo $distributor['distributorID']; ?>">
            <?php echo $distributor['distributorName']; ?>
        </option>
      <?php endforeach; ?>
    </select>
    <br>
    <label>Order Code:</label>
    <input type="text" name="code">
    <br>
    <label>Customer Name:</label>
    <input type="text" name="name">
    <br>
    <label>Order Date:</label>
    <input type="text" id="date" name="date">
    <br>
    <label>&nbsp;</label>
    <input type="submit" value="Add order">
    <br>
  </form>
  <p class="last_paragraph">
    <a href="index.php?action=list_orders">View order List</a>
  </p>
</main>
jQueryDatePicker显示甚至填充表单字段,但MyDB中的表显示“0000-00-00”

我的问题是:如何获取DatePicker数据,并将其转换为MySql将存储的日期格式

谢谢你花时间看我的问题


你好,Buhlahkay。

  • 确保您使用的数据库结构的日期是使用日期格式。。 mysql的日期字段被接受
    2017-12-30(年-月日期)

  • 调试您自己的代码输出
    echo$_POST['date']
    并查看其格式化数据库是否接受格式的日期(年-月-日)

  • 将日期选择器Jquery修改为
    $('#Date').datepicker({dateFormat:'yy-mm-dd'})

  • 如果显示格式,则没有问题。。请正确地重新更新代码,因为what does index.php正在做一些更详细的1乘1操作。为了避免混淆


您是否尝试打印以筛选插入DB中的值?也许
$date
变量没有您认为的那样。您推荐的日期选择器Jquery修改(第三个要点)解决了我的问题,现在日期从日期选择器发送到数据库。谢谢!你提到重新上传代码。您希望我在哪里执行此操作?@Buhlahkay修改
$(“#date”).datepicker()
$('#date')。日期选择器({dateFormat:'yy-mm-dd'})
然后通过
echo$\u POST['date']检查输出结果了解日期是如何输出的(yyyy月日期)
<!DOCTYPE html> 
<!-- This header page is going to be used with my Order Schedule PHP Program and main_two.css-->
<html>
  <!-- This is the body section-->
  <head>
    <title>Order Status</title>
      <link rel='stylesheet' type='text/css' href = "../main_two.css">

        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
          <title>jQuery UI Datepicker - Default functionality</title>
          <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
          <link rel="stylesheet" href="/resources/demos/style.css">
          <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
          <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
          <script>

          $( function(){
            $( "#date" ).datepicker();
          } );
          </script>

  </head>
  <!-- This is the body section-->
  <body>

  <header>
    <h1>My PHP Sandbox - Date Picker</h1>

  </header>
    function add_order($distributor_id, $code, $name, $date){
  global $db;
  $query = 'INSERT INTO orders
                (distributorID, orderCode, orderName, orderDate)
            VALUES
                (:distributor_id, :code, :name, :date)';
  $statement = $db->prepare($query);
  $statement->bindValue(':distributor_id', $distributor_id);
  $statement->bindValue(':code', $code);
  $statement->bindValue(':name', $name);
  $statement->bindValue(':date', $date);
  $statement->execute();
  $statement->closeCursor();
}
?>
<!-- Display table of orders -->
  <h2><?php echo $distributor_name; ?></h2>
  <table>
    <tr>
      <th>Order Code</th>
      <th>Order Name</th>
      <th>Order Date</th>
      <th>&nbsp;</th>
    </tr>
    <?php foreach ($orders as $order) : ?>
      <tr>
        <td><?php echo $order['orderCode']; ?></td>
        <td><?php echo $order['orderName'] ?></td>
        <td><?php echo $order['orderDate'] ?></td>
        <td><form action="." method="post">
          <input type="hidden" name="action" value="delete_order">
          <input type="hidden" name="order_id" value="<?php echo $order['orderID']; ?>">
          <input type="hidden" name="distributor_id" value="<?php echo $order['distributorID']; ?>">
          <input type="submit" value="Delete">
        </form></td>
      </tr>
    <?php endforeach; ?>
  </table>
  <p class = "last_paragraph">
    <a href="?action=show_add_form">Add order</a>
  </p>

    ***<h2>This is a test to output $date: <?php echo $date; ?></h2>
    <h2>This is a test to output echo $_POST['date']: <?php echo*** $_POST['date']; ?></h2>