我是 php 新手,只是为了警告你。无论如何,我已经查了很多,但看到我不太了解..我看不出该怎么做..所以我有一个表,里面有一个“日期”列,我正在测试使用表单将值插入表中。我想要它,这样我就可以在表单中拆分日期(例如月:日:年)并将它们组合成一个值以插入“日期” ' 列..任何想法如何做到这一点?我试过 implode() 但我不确定这些值是如何从表单发送的,所以......使用代码:
实际形式
<form action="submit.php" method="post" style="text-align: center; width: 550px; margin: auto;">
<!--Id: <input type="text" name="id"> -->
<div style="float: left;">Author: <input type="text" name="author"></div>
<div style="float: right;">Month: <input type="text" name="month" size="3">
Day: <input type="text" name="day" size="3">
Year: <input type="text" name="year" size="5"><br></div>
<textarea name="post" style="width: 550px; height: 100px;"></textarea><br>
<input type="submit">
</form>
</body>
提交.php
<?php
mysql_connect('localhost','root');
mysql_select_db('apple');
$date = implode("-", "(month, day, year)");
$sql = "INSERT INTO blog (id, author, $date, post) VALUES ('$_POST[id]', '$_POST[author]', '$_POST[date]', '$_POST[post]')";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
?>