简体   繁体   English

为什么不能在MySQL上的数据库中保存当前日期?

[英]why can't I save the current date in my database on mysql?

why can't I save the current date in my database on mysql, all columns here enter except the date which only displays 0000-00-00 in the database 为什么我不能在MySQL上的数据库中保存当前日期,所以这里的所有列都输入,除了仅在数据库中显示0000-00-00的日期

<?php
require_once 'koneksi.php';

if (isset($_POST['submit'])) {
    foreach ($_POST['keterangan'] as $id => $keterangan) {
        $nama_siswa = $_POST['nama_siswa'][$id];
        $kelas = $_POST['kelas'][$id];
        $peminatan = $_POST['peminatan'][$id];
        $waktu = date("Y-m-d H:i:s");

        $sql = "INSERT INTO kehadiran VALUES ('','$nama_siswa', '$kelas', '$peminatan', '$keterangan', $waktu  )";
        $result = mysqli_query($conn, $sql);

if ($result) {
            header("location:index.php?page=home.php"); 
        } else {
            echo "failed data added";
        }
  }
}


?>

今天的日期列输入失败,根据图像显示数据

You should put CURDATE() function in the code replacing 您应该将CURDATE()函数放入代码替换中

$waktu $ waktu

From an initial look, it seems you forgot to enclose your variable $waktu with single quote, as in Mysql datetime values should be enclosed by quotes similar to string values. 初步看来,您似乎忘记了用单引号将变量$waktu括起来,因为在Mysql中,datetime值应该用类似于字符串值的引号括起来。 so the query should be updated as following: 因此查询应更新如下:

$sql = "INSERT INTO kehadiran VALUES ('','$nama_siswa', '$kelas', '$peminatan', '$keterangan', '$waktu'  )"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我无法将pdf块放入mysql数据库? - Why can't I get my chunks of pdf into the mysql database? 为什么我无法访问数据库? - why i can't reach my database? 我为什么不能(或如何)使用WordPress API将NULL值插入我的MySQL数据库中 - Why can't I — or how do I — insert NULL values into my MySQL database using the WordPress API 我想将服务器的当前日期与存储在mySQL数据库中的日期进行比较 - I want to compare the current date of my server with a date stored in a mySQL database 为什么我不能使用“必需”功能编写MySQL数据库? - Why can't i write my MySQL database using a 'required' function? 为什么我不能在MySQL数据库的时间戳字段中添加时间戳值? - Why I can't add timestamp value to my timestamp field in mysql database? 为什么我无法连接到我的sql数据库? 我收到错误消息:“无法通过套接字连接到本地MySQL服务器” - Why can't I connect to my sql database? I get the error message: “Can't connect to local MySQL server through socket” 为什么无法更新连接到我的Android应用程序的MySQL数据库? - Why can't a MySQL database, connected to my android app, be updated? 为什么我无法将数据保存到我的文本文件中? - Why I can't save the data into my text file? 为什么我的数据无法保存到MySQL? - Why won't my data save to MySQL?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM