0

将数据插入数据库时​​出现问题。但是当我回显时,它不会重复。这是我的代码:

    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");
    }

我不知道我的代码哪里错了,因为它不会给我错误。:/

4

1 回答 1

3
$result2 = mysql_query($query)

那应该是

$result2 = mysql_query($query2)

这就是为什么您应该将变量命名为比$query. 请仔细阅读:http ://bobby-tables.com/php.html

于 2013-08-05T08:25:16.503 回答