duanqian6295 2015-02-28 06:26
浏览 91
已采纳

Php无法通过HTML表单更新MySQL表中的日期

I cannot solve this seemingly simply problem. I have an HTML form posting to a php file which works perfectly well. However, when I post a date value from HTML to php the MySQL database updates all the required fields except the date which still shows as 0000-00-00. When I change the php variable to CURDATE() it works OK however, I do not require the current date but the date I post from my HTML file. This is my 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;">

The input date I am passing from this HTML to php is:

<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" >

My php file (I am only including the relevant part) reads as follows:

<?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'"; 

My var_dump correctly displays: string(10) "2015-02-26" for the string $cndate which is the value I am trying to pass but for some reason it is still updating as 0000-00-00.

Thanks

  • 写回答

2条回答 默认 最新

  • dongxu8533486 2015-02-28 07:06
    关注

    While inserting put $cndate in single quote '$cndate'.

    Also do check data type of cndate field

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,