以下代码适用于从表单插入数组,但它将每个值插入到它自己的行中。如何将数组插入一行?
<?php
require_once('config.php');
require_once('open_db.php');
$palette=$_POST['colors_palette'];
while (list ($key,$val) = @each ($palette)) {
}
For ($i=0; $i<sizeof($palette);$i++) {
$query="INSERT INTO style_test1 (colors_palette) VALUES ('".$palette[$i]."')";
Mysql_query($query) or die(mysql_error());
}
Echo "Record is inserted";
?>
<form method="post" action="insert_array.php" >
<input type="checkbox" name="colors_palette[]" value="jewel" />
<input type="checkbox" name="colors_palette[]" value="bright" />
<input type="checkbox" name="colors_palette[]" value="soft" />
<input type="checkbox" name="colors_palette[]" value="earth" />
<input type="submit" name="Submit" value="Submit" />
</form>