Tim*_*nto 1 php mysql date insert
这是我的表单代码
*我的数据库使用日期格式
我确定我的代码没有错误,但是只要我点击上传按钮,日期就只有 0000-00-00
<form action="imageupload.php" method="post" enctype="multipart/form-data">
<label for="date">Date</label>
<input type="date" size="60" name="date" id="date"/>
<input type="submit" value="Upload File" />
<input type="reset" value="Clear" />
</form>
Run Code Online (Sandbox Code Playgroud)
这是我的图片 upload.php 代码
fclose ($handle);
// Commit image to the database
$date = htmlentities($_POST['date']);
$query = 'INSERT INTO user_post (date) VALUES ("' . date '")';
if ( !(mysql_query($query,$link)) )
{
die('<p>Error writing image to database</p></body></html>');
}
else
{
header('Refresh: 2 ; url=imageShow.php');
}
Run Code Online (Sandbox Code Playgroud)
您需要先将日期转换为Y-m-d格式,并且还$缺少值日期,它应该是$date尝试
$rawdate = htmlentities($_POST['date']);
$date = date('Y-m-d', strtotime($rawdate));
$query = "INSERT INTO user_post (date) VALUES ('$date')";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20609 次 |
| 最近记录: |