我无法解决这个看似简单的问题。我有一个HTML表单发布到PHP文件,非常好用。但是,当我将日期值从HTML发布到php时,MySQL数据库会更新所有必需的字段,但日期仍显示为0000-00-00。当我将php变量更改为CURDATE()时,它可以正常工作,但我不需要当前日期,而是我从HTML文件发布的日期。这是我的HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Credit Note Generator v.2</title>
<meta name="generator" content="">
</head>
<body>
<div id="space"><br></div>
<div id="container">
<div id="wb_Form1" style="position:absolute;left:210px;top:110px;width:530px;height:381px;z-index:4;">
<form name="cnote" method="post" action="cnote.php" id="cnote">
<input type="number" id="dupid" style="position:absolute;left:240px;top:31px;width:207px;height:20px;line-height:20px;z-index:0;" name="dupid" value="" required="required">
<input type="date" id="cndate" style="position:absolute;left:240px;top:81px;width:207px;height:20px;line-height:20px;z-index:1;" name="cndate" value="" required="required" >
<textarea name="cnreason" id="cnreason" style="position:absolute;left:240px;top:141px;width:202px;height:127px;z-index:2;" rows="6" cols="24" required="required"></textarea>
<input type="submit" id="Button1" name="" value="Generate" style="position:absolute;left:220px;top:310px;width:132px;height:47px;z-index:3;">
我从这个HTML传递给php的输入日期是:
<input type="date" id="cndate" style="position:absolute;left:240px;top:81px;width:207px;height:20px;line-height:20px;z-index:1;" name="cndate" value="" required="required" >
我的php文件(我只包括相关部分)内容如下:
<?php
var_dump($_POST);
$con = mysql_connect("192.168.10.223","user","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("BMS", $con);
$pass = $_POST["dupid"];
$cnotes = $_POST["cnreason"];
$cndatepost = $_POST["cndate"];
$cndate2 = strtotime($cndatepost);
$cndate = date('Y-m-d',$cndate2);
//get highest
$sqlgethighest = mysql_query("SELECT MAX(CN_No) FROM Main_Data_Table");
$row = mysql_fetch_array($sqlgethighest);
$cnoteno=($row['MAX(CN_No)'])+1;
$sql="INSERT INTO Main_Data_Table (ID, Name, Surname, TitleID, NationalityID,
Age, AgentID, `Course Start`, `Course End`, CourseTypeID, `Rate per unit`,
`Arrival Date`, `Departure Date`, `Arrival Time`, `Departure Time`, `Arrival Flight`,
`Departure Flight`, AccommodationID, HostFamilyID, `Rate per night`, TransferId,
`Material Fee`, `Total Units Booked`, `Reg Fee`, BoardBasisID, `Ref Fee Acc`,
Notes, Notes2, DateofCanx, ReasonforCanx, HFXId, old_Invoice_number, LevelID,
Hide, Alloc_CodeAMID, Alloc_CodePMID, Lunch, Binder, `Audio CD`, `CD-ROM/Web`,
Tours, PromoMat, TrfFee, Settle_Bill, Commission, Pay_Local, Settle_Bill_rcpt,
Pay_on_AC, Pay_on_AC_amt, Pay_on_AC_rcpt, Deposit, SageExportNo, Invoice_number,
TrfRateCode, `Extra Commission`, F56, F57, HOT_CONF, Room_type_ID, Invoice_Date,
CN_Date, CN_No, Passport_No, DOB, CN_Presence, Corresp_CN)
SELECT NULL, Name, Surname, TitleID, NationalityID, Age, AgentID, `Course Start`,
`Course End`, CourseTypeID, `Rate per unit`, `Arrival Date`, `Departure Date`,
`Arrival Time`, `Departure Time`, `Arrival Flight`, `Departure Flight`,
AccommodationID, HostFamilyID, `Rate per night`, TransferId, `Material Fee`,
`Total Units Booked`, `Reg Fee`, BoardBasisID, `Ref Fee Acc`, CONCAT('Ref Invoice number: ', Invoice_number, ' ', '$cnotes'), Notes2,
DateofCanx, ReasonforCanx, HFXId, old_Invoice_number, LevelID, Hide,
Alloc_CodeAMID, Alloc_CodePMID, Lunch, Binder, `Audio CD`, `CD-ROM/Web`,
Tours, PromoMat, TrfFee, 0, Commission, 0, 0, 0, 0, 0, 0, 0, 0, TrfRateCode,
`Extra Commission`, F56, F57, HOT_CONF, Room_type_ID, NULL, $cndate, $cnoteno, NULL, NULL, 0, NULL
from Main_Data_Table WHERE ID='$pass'";
我的var_dump正确显示:string(10)&#34; 2015-02-26&#34;对于字符串$ cndate这是我试图传递的值但由于某种原因它仍然在更新为0000-00-00。
由于
答案 0 :(得分:1)
数据库无法存储来自html的date
类型数据...您需要将数据库的date
条目更改为varchar
才能存储html {{1} }类型..
答案 1 :(得分:1)
将$ cndate插入单引号&#39; $ cndate&#39;。
还要检查cndate字段的数据类型