gpt4 book ai didi

PHP STR_TO_DATE() 函数未发布

转载 作者:行者123 更新时间:2023-11-29 20:51:34 24 4
gpt4 key购买 nike

我正在尝试使用 STR_TO_DATE() 函数插入日期。由于某种原因它一直失败。有人可以帮忙吗?谢谢

HTML:

   <form action="config.php" method="POST">
Total Sales : <br><input type="text" id="total" name="total"><br>
Company Name : <br><input type="text" id="company" name="company"><br>
Sales Type : <br><input type="text" id="type" name="type"><br>
Sales Date : <br><input type="date" id="saledate" name="saledate"><br>
Date Entered : <br><input type="date" id="dateenter" name="dateenter"><br><br>
<input type="submit" value="insert">
</form>

PHP:

<?php

$con=mysqli_connect("***","***","***","***");

$Total = $_POST['total'];
$Company = $_POST['company'];
$Type = $_POST['type'];
$Saledate = $_POST['saledate'];
$Dateentered = $_POST['dateenter'];


$sql = "INSERT INTO htgsales (SaleAmount,Company,SalesType,SalesDate,DateEntered) VALUES ('$Total','$Company','$Type',STR_TO_DATE('$Saledate', '%m/%d/%Y'),STR_TO_DATE('$Dateentered', '%m/%d/%Y'))";

if(!mysqli_query($con,$sql))
{
echo 'Insert Failed';
}
else
{
echo 'Success';
}
?>

最佳答案

来自 MySQL 文档:

This is the inverse of the DATE_FORMAT() function. It takes a string str and a format string format. STR_TO_DATE() returns a DATETIME value if the format string contains both date and time parts, or a DATE or TIME value if the string contains only date or time parts. If the date, time, or datetime value extracted from str is illegal, STR_TO_DATE() returns NULL and produces a warning.

您获得的日期的 post 参数的值是多少?它们与您传递给函数的格式匹配吗?尝试对 $_POST 进行 var_dump 并粘贴这些值,以便我们检查是否有问题。

关于PHP STR_TO_DATE() 函数未发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37999301/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com