显示日期错误

时间:2013-11-29 09:58:06

标签: php html

我做了一些PHP。首先要澄清的是,*是我不想展示的隐藏文字。我每次尝试输入日期时都在徘徊为什么29/11/2013它会出现在php页面上。有人可以向我解释我哪里出错了,并给我一个正确的解释,说明为什么以及如何运作,非常感谢。

<html>
  <head>
    <title>XYZ</title>
  </head>
  <body>
    <h1>Insert into Database <i>XYZ</i> table <i>addressbook</i></h1>
      <form method="get" action="*********************************************      ">
        <b>ID:</b> <input type="text" name="ID"><br>
     <b>CARNAME:</b> <input type="text" name="CARNAME"><br>
        <b>FUELTYPE:</b> <input type="text" name="FUELTYPE"><br>
        <b>TRANSMISSION:</b> <input type="text" name="TRANSMISSION"><br>
        <b>ENGINESIZE:</b> <input type="text" name="ENGINESIZE"><br>
        <b>DOORS:</b> <input type="text" name="DOORS"><br>
        <b>TOTAL:</b> <input type="text" name="TOTAL"><br>
        <b>AVAILABLE:</b> <input type="text" name="AVAILABLE"><br>
        <b>DATEADDED:</b> <input type="text" name="DATEADDED"><br>
        <input type="submit">
    </form>
  </body>
</html>





<html>
  <head>
    <title>XYZ</title>
  </head>
  <body>
    <h1>Insert into Database <i>XYZ</i> table <i></i></h1>
    <?php
      $link = mysql_connect ("**********", "*********", "*********");
      mysql_select_db ("***********");

      $ID = $_GET["ID"];
      $CARNAME = $_GET["CARNAME"];
      $FUELTYPE = $_GET["FUELTYPE"];
      $TRANSMISSION = $_GET["TRANSMISSION"];
      $ENGINESIZE = $_GET["ENGINESIZE"];
      $DOORS = $_GET["DOORS"];
      $TOTAL = $_GET["TOTAL"];
      $AVAILABLE = $_GET["AVAILABLE"];
      $DATEADDED = $_GET["DATEADDED"];

      $query = "INSERT into CAR values ('$ID', '$CARNAME', '$FUELTYPE', '$TRANSMISSION', '$ENGINESIZE', '$DOORS', '$TOTAL', '$AVAILABLE', '$DATEADDED')";
      $result = mysql_query ($query);

      $query = "SELECT * from CAR";
      $result = mysql_query ($query);

      print "<table>";
      print "<tr>";
      print "<th>ID</th><th>CARNAME</th><th>FUELTYPE</th><th>TRANSMISSION</th><th>ENGINESIZE</th><th>DOORS</th><th>TOTAL</th><th>AVAILABLE</th><th>DATEADDED</th>";
      print "</tr>";
      for ($i = 0; $i < mysql_num_rows ($result); $i ++)
      {        
        $row = mysql_fetch_object ($result);
        print "<tr>";
        print "<td>$row->ID</td>";
     print "<td>$row->CARNAME</td>";
        print "<td>$row->FUELTYPE</td>";
        print "<td>$row->TRANSMISSION</td>";
        print "<td>$row->ENGINESIZE</td>";
        print "<td>$row->DOORS</td>";
        print "<td>$row->TOTAL</td>";
        print "<td>$row->AVAILABLE</td>";
        print "<td>$row->DATEADDED</td>";
        print "</tr>";
      }
      print "</table>";
      mysql_close ($link);
    ?>
  </body>
</html>

2 个答案:

答案 0 :(得分:0)

在MySql中,您的数据应格式为yyyyMMdd,因此您应该在插入之前先将其转换

$DATEADDED = $_GET["DATEADDED"];

变得类似

$DATEADDED = date("Y-m-d", strtotime($_GET["DATEADDED"]));

答案 1 :(得分:0)

检查数据库中的日期格式Y / m / d或是否设置为日期...否则将其更改为varchar(255)以包含任何格式。