• <legend id='8GvmB'><style id='8GvmB'><dir id='8GvmB'><q id='8GvmB'></q></dir></style></legend>
  • <tfoot id='8GvmB'></tfoot>

  • <small id='8GvmB'></small><noframes id='8GvmB'>

    <i id='8GvmB'><tr id='8GvmB'><dt id='8GvmB'><q id='8GvmB'><span id='8GvmB'><b id='8GvmB'><form id='8GvmB'><ins id='8GvmB'></ins><ul id='8GvmB'></ul><sub id='8GvmB'></sub></form><legend id='8GvmB'></legend><bdo id='8GvmB'><pre id='8GvmB'><center id='8GvmB'></center></pre></bdo></b><th id='8GvmB'></th></span></q></dt></tr></i><div id='8GvmB'><tfoot id='8GvmB'></tfoot><dl id='8GvmB'><fieldset id='8GvmB'></fieldset></dl></div>
      <bdo id='8GvmB'></bdo><ul id='8GvmB'></ul>

      1. 如何使用 mySQL 通过 PHP 向 INSERT 添加日期和时间戳?

        时间:2023-10-30
        • <i id='k5O4j'><tr id='k5O4j'><dt id='k5O4j'><q id='k5O4j'><span id='k5O4j'><b id='k5O4j'><form id='k5O4j'><ins id='k5O4j'></ins><ul id='k5O4j'></ul><sub id='k5O4j'></sub></form><legend id='k5O4j'></legend><bdo id='k5O4j'><pre id='k5O4j'><center id='k5O4j'></center></pre></bdo></b><th id='k5O4j'></th></span></q></dt></tr></i><div id='k5O4j'><tfoot id='k5O4j'></tfoot><dl id='k5O4j'><fieldset id='k5O4j'></fieldset></dl></div>

          1. <legend id='k5O4j'><style id='k5O4j'><dir id='k5O4j'><q id='k5O4j'></q></dir></style></legend>
              <bdo id='k5O4j'></bdo><ul id='k5O4j'></ul>

              1. <tfoot id='k5O4j'></tfoot>

                    <tbody id='k5O4j'></tbody>

                  <small id='k5O4j'></small><noframes id='k5O4j'>

                  本文介绍了如何使用 mySQL 通过 PHP 向 INSERT 添加日期和时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个带有 mySQL 的插入脚本.我需要将创建记录的日期和时间放在add_time"列中.

                  I have an insert script with mySQL. I need to place the date and time when the record is created in the 'add_time" column.

                  谁能告诉我如何修改我现有的脚本来做到这一点?我需要单独的 PHP 脚本吗?

                  Can anyone show me how to modify my existing script to do this? Do I need a separate PHP script?

                  我希望日期以标准格式显示:09/25/11 6:54 AM

                  I would like the date to appear in standard formt: 09/25/11 6:54 AM

                  <?
                    $host="XXXXXXXXXXX";
                    $username="XXXXXXX";
                    $password="XXXXXXX";
                    $db_name="naturan8_hero";
                    $tbl_name="cartons_added";
                  
                    mysql_connect("$host", "$username", "$password") or die("cannot connect");
                    mysql_select_db("$db_name")or die("cannot select DB");
                  
                    $order = "INSERT INTO cartons_added (
                        type,
                        part_no,
                        add_type,
                        add_qty,
                        add_ref,
                        add_by,
                        add_notes
                      ) VALUES (
                        '$_POST[type]', 
                        '$_POST[part_no]', 
                        '$_POST[add_type]', 
                        '$_POST[add_qty]', 
                        '$_POST[add_ref]', 
                        '$_POST[add_by]', 
                        '$_POST[add_notes]'
                      )";
                  
                    $result = mysql_query($order);
                  
                    if ($result) {
                      $part_no = $_REQUEST['part_no'] ;
                      $add_qty = $_REQUEST['add_qty'];
                      header("location: inv_fc_add_success.php?part_no=" . urlencode($part_no) . "&add_qty=" . urlencode($add_qty));
                    }
                    else {
                      header("location: inv_fc_add_fail.php");
                    }
                  ?>
                  

                  推荐答案

                  您在数据库中设置了add_time"列吗?是DATETIME格式吗?

                  You got the "add_time" column set up in your database? Is it of DATETIME format?

                  在这种情况下,您可以像这样修改您的查询:

                  In that case you may just modify your query like this:

                  $order = "INSERT INTO cartons_added (type, part_no, add_type, add_qty, 
                    add_ref, add_by, add_notes, add_time)
                  
                    VALUES
                    ('$_POST[type]', 
                    '$_POST[part_no]', 
                    '$_POST[add_type]', 
                    '$_POST[add_qty]', 
                    '$_POST[add_ref]', 
                    '$_POST[add_by]', 
                    '$_POST[add_notes]',
                     NOW())";
                  

                  尽管您应该知道执行这样的查询是危险的,因为您相信用户只会输入好东西!谷歌SQL 注入"以了解更多信息,mysql_real_escape_string() 也是如此.

                  Though you should be aware that executing queries like this is dangerous as you trust the user to input only nice things! Google "SQL Injection" to find out more about it, mysql_real_escape_string(), too.

                  这篇关于如何使用 mySQL 通过 PHP 向 INSERT 添加日期和时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:多次运行 MySQL INSERT Query(将值插入多个表) 下一篇:创建一个动态的php插入到mysql函数中?

                  相关文章

                    <bdo id='8jS8W'></bdo><ul id='8jS8W'></ul>

                    <legend id='8jS8W'><style id='8jS8W'><dir id='8jS8W'><q id='8jS8W'></q></dir></style></legend>

                    1. <small id='8jS8W'></small><noframes id='8jS8W'>

                      <i id='8jS8W'><tr id='8jS8W'><dt id='8jS8W'><q id='8jS8W'><span id='8jS8W'><b id='8jS8W'><form id='8jS8W'><ins id='8jS8W'></ins><ul id='8jS8W'></ul><sub id='8jS8W'></sub></form><legend id='8jS8W'></legend><bdo id='8jS8W'><pre id='8jS8W'><center id='8jS8W'></center></pre></bdo></b><th id='8jS8W'></th></span></q></dt></tr></i><div id='8jS8W'><tfoot id='8jS8W'></tfoot><dl id='8jS8W'><fieldset id='8jS8W'></fieldset></dl></div>
                      <tfoot id='8jS8W'></tfoot>