试图在我的 mySQL 数据库中插入多个值,这就是我到目前为止所得到的。
if (in_array(",", $_POST['categories'])) { /* Other was selected */}
$cat = implode(" ,", $_POST['categories']);
if (in_array(",", $_POST['subcat'])) { /* Other was selected */}
$sub = implode(" ,", $_POST['subcat']);
if (in_array(",", $_POST['type'])) { /* Other was selected */}
$type = implode(" ,", $_POST['type']);
if (in_array(",", $_POST['payment'])) { /* Other was selected */}
$payment = implode(" ,", $_POST['payment']);
$sql = "INSERT INTO tbl_locations SET
name='".$_POST['name']."',
alias='".$_POST['alias']."',
category_id='$cat',
subcategory_id='$sub',
tourism_type_id='$type',
lgu_id='$payment',
latitude='".$_POST['latbox']."',
longitude='".$_POST['lngbox']."'
";
$qry= mysql_query($sql) or die (mysql_error());
if ($qry)
{
header("location:addsuccess.php");
exit();
}
如您所见,不仅有 1 个多个条目,还有 4 个。. 将不胜感激如何进行此操作。..我的表格也name=name[]
没有问题。它只是将单个值插入到我的数据库中,而不是多个。