-1

大家好,我使用 fetch 数组创建了一些脚本来显示我的结果,但现在我遇到了问题,如何将数据结果插入到新表中

---第一页

<?php
 while ($row = mysql_fetch_array($query)) {
 echo "<tr>";
 echo "<td><input type=\"text\" name=\"grouping\" value=\"".stripslashes('NINS_LEC')."\" /></td>";
echo "<td><input type=\"text\" name=\"InvoiceAccNum\" value=\"". stripslashes($row['InvoiceAccNum'])  ."\" /> </td>";
 echo "<td><input type=\"text\" name=\"AccountFirstName\" value=\"".    stripslashes($row['AccountFirstName']) . "\" /></td>";
 echo "<td><input type=\"text\" name=\"SubsidiaryCode\" value=\"". stripslashes($row['SubsidiaryCode']) ."\" /></td>";
 echo "<td><input type=\"text\" name=\"HandlingCode\" value=\"" . stripslashes($row['HandlingCode']) . "\" /></td>";
           echo "</tr>";
       }
    ?>
</table>
   <?echo "$num_rows Rows\n";?>
 <? echo 
"<form name='vw_ob_save' method='get'>
<fieldset>
<table width='680'><tr>
<td colspan='4' align='center'>
<input type='submit' name='btn_save' value='Save'>
</td></tr></table></fieldset></form>";
if(isset($_POST['btn_save'])){
include 'grouping.php';
if($query1>0){
msgalert("data save!");}
}?>

这个现在正在工作,但是当我的 grouping.php 页面执行时,我的表中只保存了 1 个数据。

分组.php

    <?php
    session_start();
    $username = "root";
    $password = "";
    $hostname = "localhost"; 

    //connection to the database
    $dbhandle = mysql_connect($hostname, $username, $password)
    or die("Unable to connect to MySQL");
    echo "";

    $selected = mysql_select_db("bsswebtool",$dbhandle)
    or die("Could not select bsswebtool");

    if(empty($_POST['form1']))
    {

$grouping                = $_POST['grouping'];
$InvoiceAccNum       = $_POST['InvoiceAccNum'];
$AccountFirstName        = $_POST['AccountFirstName'];
$SubsidiaryCode       = $_POST['SubsidiaryCode'];
$HandlingCode           = $_POST['HandlingCode'];
    }
    else
    {

    $grouping                =null;
$InvoiceAccNum           =null;
$AccountFirstName        =null;
$SubsidiaryCode          =null;
$HandlingCode            =null;
}

 $query1 = "INSERT INTO nins_lec (rid,grouping,InvoiceAccNum,AccountFirstName,SubsidiaryCode,HandlingCode)
 values 
        ('','$grouping','$InvoiceAccNum','$AccountFirstName','$SubsidiaryCode','$HandlingCode')";

mysql_query($query1);

   ?>

我预计我的数据库中有 9 行受到影响,但在检查我的数据库示例数据结果时只插入了 1 行

   Groupings InvoiceAccNum  AccountFirstName       SubsidiaryCode   HandlingCode
  NINS_LEC    0000000000    ana                             XXXX        D
  NINS_LEC    0000000000    tiana                           XXXX        Q
  NINS_LEC    0000000000    LOPEZ KARL CHU                  XXXX        Q
  NINS_LEC    0000000000    pepe                            XXXX        Q
  NINS_LEC    0000000000    SANTOS                          XXXX        R
  NINS_LEC    0000000000    WONG                            XXXX        Q 
  NINS_LEC    0000000000    BERNALDEZ                       XXXX        R
  NINS_LEC    0000000000    PALICOS                         XXXX        Q
  NINS_LEC    0000000000     JOSE                           XXXX        Q
  9 Rows  
4

2 回答 2

0
  <form name='vw_ob_save' method='get'>

  ...

   $_POST['grouping'];

When your form useses get then you cant access request via $_POST on your php scirpt!

于 2013-09-23T08:26:14.630 回答
0

rid表的主 ID(唯一/主键)吗?如果是这样,请将其从 INSERT 中删除。我更正了下面缺少的逗号!

$query1 = "INSERT INTO nins_lec (rid, grouping, InvoiceAccNum , AccountFirstName, Subsidiary, CodeHandlingCode)
values ('', '$grouping', '$InvoiceAccNum', '$AccountFirstName', '$SubsidiaryCode', '$HandlingCode')";
于 2013-09-23T08:29:25.590 回答