我的网站很简单,我要做的就是将我在日期选择器中选择的日期插入 MySQL。(目前它像这样插入“0000-00-00 00:00:00”)。
我的 PHP/HTML 代码是:
<form id="form_351400" class="appnitro" method="post" action="insert.php">
<div class="form_description">
<div style="width:100%;border:0px solid #000;">
<div style="float:left; width:75%;">
<h2 align="left">Samurai Digital d.o.o.</h2>
<p>
Maintenance Team
</p>
</div>
<div style="float:left; width:25%;">
<a href="index.php"><img src="samurai.png" alt="Samurai" width="150" height="150" /></a>
</div>
<div style="clear:both;"></div>
</div>
</div>
<ul >
<li id="li_0" >
<label class="description" for="element_0">Insert into DB </label>
<br/>
</li>
<li id="li_1" >
<label class="description" for="element_1" name="id" >ID </label>
<input type="text" name="id" />
</li>
<li id="li_2" >
<label class="description" for="element_3">Date </label>
<span>
<input id="element_3_1" name="element_3_1" class="element text" size="2" maxlength="2" value="" type="text">
/ <label for="element_3_1">MM</label>
</span>
<span>
<input id="element_3_2" name="element_3_2" class="element text" size="2" maxlength="2" value="" type="text">
/ <label for="element_3_2">DD</label>
</span>
<span>
<input id="element_3_3" name="element_3_3" class="element text" size="4" maxlength="4" value="" type="text">
<label for="element_3_3">YYYY</label>
</span>
<span id="calendar_3"> <img id="cal_img_3" class="datepicker" src="calendar.gif" alt="Pick a date."> </span>
<script type="text/javascript">
Calendar.setup({
inputField : "element_3_3",
baseField : "element_3",
displayArea : "calendar_3",
button : "cal_img_3",
ifFormat : "%B %e, %Y",
onSelect : selectDate
});
</script>
</li>
<li id="li_3" >
<label class="description" for="element_2" name="refid" >Refid </label>
<input type="text" name="refid" />
</li>
<li id="li_4" >
<label class="description" for="element_4" name="classification" >Classification </label>
<select name="classification">
<option value="SECRET">SECRET</option>
<option value="SECRET//NOFORN">SECRET//NOFORN</option>
<option value="CONFIDENTIAL">CONFIDENTIAL</option>
<option value="CONFIDENTIAL//NOFORN">CONFIDENTIAL//NOFORN</option>
<option value="UNCLASSIFIED">UNCLASSIFIED</option>
<option value="UNCLASSIFIED//FOR OFFICIAL USE ONLY">UNCLASSIFIED//FOR OFFICIAL USE ONLY</option>
</select>
</li>
<li id="li_5" >
<label class="description" for="element_5" name="origin" >Origin </label>
<input type="text" name="origin" />
</li>
<li id="li_6" >
<label class="description" for="element_6" name="destination" >Destination </label>
<input type="text" name="destination" />
</li>
<li id="li_7" >
<label class="description" for="element_7" name="header" >Header </label>
<input type="text" name="header" />
</li>
<li id="li_8" >
<label class="description" for="element_8" name="content" >Content </label> <textarea rows="15" cols="40" name="content"></textarea>
<br/>
</li>
<input type="Submit" />
</ul >
</form>
还有一个连接到我的 MySQL 的 PHP:
<?php
$id = $_POST['element_1'];
$date = $_POST['element_3_3'].'-'.$_POST['element_3_1'].'-'.$_POST['element_3_2'];
$refid = $_POST['element_2'];
$classification = $_POST['element_4'];
$origin = $_POST['element_5'];
$destination = $_POST['element_6'];
$header = $_POST['element_7'];
$content = $_POST['element_8'];
$con = mysql_connect("localhost","XXXXXX","XXXXXX");
if (!$con)
{
die('Error connecting to mysql server: ' . mysql_error());
}
mysql_select_db("XXXXXX", $con);
$sql="INSERT INTO emails (id, date, refid, classification, origin, destination, header, content)
VALUES
('$_POST[id]','$_POST[date]','$_POST[refid]','$_POST[classification]','$_POST[origin]','$_POST[destination]','$_POST[header]','$_POST[content]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
所有其他表格都在工作,我可以添加它们,除了日期。也许是因为我以错误的方式将 DAY / MONTH / YEAR 添加为一个字符串。