我想使用php中的数组在mysql表中插入表单记录。
我这样做但是没有用。
if(isset($_POST['subimt'])){
$query = "INSERT INTO item (`id`, `1`, `2`, `3`, `4`, `5`) VALUES ";
foreach($_POST['name'] as $i => $name)
{
$item = $_POST['item'];
$name = $_POST['name'];
$price = $_POST['price'];
$quantity = $_POST['quantity'];
$total = $_POST['total'];
// Add to database
$query = $query." (NULL, '$item', '$name', '$price', '$quantity', '$total'),";
}
$query = substr($query,0,-1); //remove last char
$result = mysql_query($query);
}
?>
此代码未在mysql表中插入任何记录。提前谢谢