我的HTML表单是这样的:如何插入时间格式在MySQL
<html>
<head>
<body>
<form action='upload_data.php' method="POST" enctype="multipart/form-data">
<input type="text" name="total_container">
<button id="submit">Add</button>
</form>
</body>
</head>
</html>
upload_data.php
include 'connect.php';
$total_container = $_POST["total_container"];
if (!empty($total_container)){
$fill="INSERT INTO `container`(`total_container`, `time`)VALUES($total_container,'blabla')";
$data=mysql_query($fill);
if(isset($data)){
echo "<script>alert ('Great');</script>";
} else {
echo "<script>alert('No...');</script>";
}
}
我要填写我的数据库表(容器)是这样的:
id_block | total_container | time |
---------------------------------------
1 | 1 | 00:00:20 |
2 | 2 | 00:00:40 |
3 | 3 | 00:01:00 |
4 | 6 | 00:02:00 |
- id_block is auto_increment
- 对于每个total_container,其乘以20秒的时间字段。
那么,我应该怎么做我的查询?,我想自动填充时间字段,乘以20秒。
参考值就存储为一个int,只是做$ total_container * 20,当你得到它,你可以很容易地计算得到secounds/min/hours? – Naruto 2014-10-31 15:07:56
由于你的用户参数没有[正确转义](http://bobby-tables.com/php),所以这看起来恐怖不安全。您应该**绝不**将'$ _POST'数据直接放入查询中。这造成了一个巨大的[SQL注入漏洞](http://bobby-tables.com/)。另外,'mysql_query'是一个过时的接口,不应该被使用,它将被从PHP中删除。像[PDO这样的现代化替代品并不难学](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/)。像[PHP The Right Way](http://www.phptherightway.com/)这样的指南解释了最佳实践。 – tadman 2014-10-31 15:51:58