保存按钮,将保存我本地主机表中的数据

时间:2013-09-23 08:14:42

标签: php mysql

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

---第1页

<?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个数据保存。

grouping.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  

2 个答案:

答案 0 :(得分:0)

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

  ...

   $_POST['grouping'];

当您的表单使用获取时,您无法通过PHP脚本上的$ _POST访问请求!

答案 1 :(得分:0)

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

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