将数据插入数据库时出现问题。但是当我回显时,它不会重复。这是我的代码:
foreach($_POST['purpose'] as $i => $a){
echo $a."-".$i."<br />";
if($_POST['purpose'][$i] == "recieved"){
$purpose[$i] = "'1','0','0','0','0'";
} elseif($_POST['purpose'][$i] == "released"){
$purpose[$i] = "'0','1','0','0','0'";
} elseif($_POST['purpose'][$i] == "recalled"){
$purpose[$i] = "'0','0','1','0','0'";
} elseif($_POST['purpose'][$i] == "charges"){
$purpose[$i] = "'0','0','0','1','0'";
} elseif($_POST['purpose'][$i] == "adjustments"){
$purpose[$i] = "'0','0','0','0','1'";
}
$query = "INSERT INTO responsibility_center VALUES(
'',
'".$_POST['or_number']."',
'".$_POST['response'][$i]."',
$purpose[$i])";
echo $query."<br />";
$result1 = mysql_query($query) or die(mysql_error()." inserting responsibility center");
$responseid = mysql_insert_id();
$query2 = "INSERT INTO particulars VALUES (
'',
'".$responseid."',
'".$_POST['details'][$i]."')";
echo $query2."<br />";
$result2 = mysql_query($query) or die(mysql_error()." inserting particulars");
}
我不知道我的代码哪里错了,因为它不会给我错误。:/