Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.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
Php 将日期转换为荷兰语格式_Php_Mysql - Fatal编程技术网

Php 将日期转换为荷兰语格式

Php 将日期转换为荷兰语格式,php,mysql,Php,Mysql,我想在MySQL中以荷兰语格式输入日期。现在他给了我标准格式。我需要在输出列表或插入文件中更改它吗 这是我的插入代码: <?php session_start(); include '../dbh.php'; $costname = $_POST['costname']; $category = $_POST['category']; $subcategory = $_POST['subcategory']; $price = $_POST['price']; $info = $_P

我想在MySQL中以荷兰语格式输入日期。现在他给了我标准格式。我需要在输出列表或插入文件中更改它吗

这是我的插入代码:

<?php
session_start();


include '../dbh.php';

$costname = $_POST['costname'];
$category = $_POST['category'];
$subcategory = $_POST['subcategory'];
$price = $_POST['price'];
$info = $_POST['info'];
$costdate = $_POST['costdate']->format("d-m-Y H:i:s");
$iduser = $_SESSION['id'];

if(empty($costname)) {
  header("Location: ../dashboard.php?error=emptycostname");
  exit();
}

if(empty($category)) {
  header("Location: ../dashboard.php?error=emptycatergory");
  exit();
}

if(empty($subcategory)) {
  header("Location: ../dashboard.php?error=emptysubcatergory");
  exit();
}

if(empty($price)) {
  header("Location: ../dashboard.php?error=emptyprice");
  exit();
}

if(empty($info)) {
  header("Location: ../dashboard.php?error=emptyinfo");
  exit();
}

 else {
  $sql = "INSERT INTO costs (costname, category, subcategory, price, info, userid, costdate)
  VALUES ('$costname', '$category', '$subcategory', '$price', '$info', '$iduser', '$costdate')";

  $result = mysqli_query($conn, $sql);

  header("Location: ../dashboard.php");

}

您可以使用MySQL的
DATE\u FORMAT
函数对其进行任意格式化。以下是如何更新select查询以对其进行格式化:

$sql_costs = "SELECT *, DATE_FORMAT(costdate, '%d-%m-%Y %H:%i:%s') AS costdate FROM costs WHERE userid='".$_SESSION['id']."'";
请在此处阅读有关
DATE\u格式
功能的更多信息:


请注意,您的代码容易受到SQL注入攻击,从而使您的服务器处于风险之中。请在此处阅读有关如何安全操作的更多信息:
$sql_costs = "SELECT *, DATE_FORMAT(costdate, '%d-%m-%Y %H:%i:%s') AS costdate FROM costs WHERE userid='".$_SESSION['id']."'";