在使用javascript添加更多行的表单中,只有一行有效


only 1 row in add more row in form using javascript is working

我有一个订单页面,其中包含从mysql中选择的下拉项。如果我点击添加更多,它是有效的,但当我输入数量时,选择项目和服务。只有最后一个被输入到数据库中,并显示在发票上。附件是屏幕截图http://pastebin.com/s9rXRGhD

http://prntscr.com/99z0e7

<!DOCTYPE html>
<?php
session_start();
include('database/AdminDao.php');
//include("includes/phpjobscheduler/firepjs.php");
if(!isset($_SESSION['username'])){
header("location:index.php");
}
include('db.php');
$gentquery1=mysql_query("SELECT * FROM clothes WHERE category_id=1 or category_id=2 or  category_id=3");
//$get=mysql_query("SELECT name FROM clothes");
//$str = mysql_query("select * from clothes  where category_id ='0' ");
$gentquery=mysql_query("SELECT * FROM clothes  WHERE category_id=1");
$ladyquery=mysql_query("SELECT * FROM clothes  WHERE category_id=2");
$householdquery=mysql_query("SELECT * FROM clothes  WHERE category_id=3");
$DbObj = new AdminDao();
$allCustomers  = $DbObj->fetchCustomers();
$customerNo =  sizeof($allCustomers);
?>
<html lang="en">
    <head>
 <link rel="stylesheet" type="text/css" href="css/DT_bootstrap.css">
<link rel="stylesheet" href="css/font-awesome.min.css">
    <style type="text/css">
      .sidebar-nav {
        padding: 9px 0;
      }
    </style>
    <link href="css/bootstrap-responsive.css" rel="stylesheet">
<link href="css/style.css" media="screen" rel="stylesheet" type="text/css" />	
<SCRIPT language="javascript">
        function addRow(tableID) {
            var table = document.getElementById(tableID);
            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);
            var colCount = table.rows[0].cells.length;
             for(var i=0; i<colCount; i++) {
                var newcell = row.insertCell(i);
                newcell.innerHTML = table.rows[0].cells[i].innerHTML;
                //alert(newcell.childNodes);
                switch(newcell.childNodes[0].type) {
                    case "text":
                            newcell.childNodes[0].value = "";
                            break;
                    case "checkbox":
                            newcell.childNodes[0].checked = false;
                            break;
                    case "select-one":
                            newcell.childNodes[0].selectedIndex = 0;
                            break;
                }
            }
        }
        function deleteRow(tableID) {
            try {
            var table = document.getElementById(tableID);
            var rowCount = table.rows.length;
            for(var i=0; i<rowCount; i++) {
                var row = table.rows[i];
                var chkbox = row.cells[0].childNodes[0];
                if(null != chkbox && true == chkbox.checked) {
                    if(rowCount <= 1) {
                        alert("Cannot delete all the rows.");
                        break;
                    }
                    table.deleteRow(i);
                    rowCount--;
                    i--;
                }
            }
            }catch(e) {
                alert(e);
            }
        }
 
    </SCRIPT>
</head>
<body>
<div id="blockorder">
               <form action="placeorder.php" method="post">
			   <label for="name"  style="float:left; width:10%;margin-top:25px;">Client Name</label>
                          <span class="formwrapper">
                            	<select data-placeholder="Select a Customer..." style="width:250px" class="chzn-select" name="name" id="name" tabindex="2">
                                    <option value=""></option>
                                        <?php
    for($index = 0; $index < $customerNo ;$index++)
    {
    ?>
    <tr class="gradeA">
        <option value="<?php  echo $allCustomers[$index]['id'] ; ?>"> <?php  echo $allCustomers[$index]['fullname'] ; ?> --- <?php  echo $allCustomers[$index]['id'] ; ?></option>
    </tr>
<?php } ?>
</select>
                            </span>
<!--               <input type="text" class="form-control" id="name" placeholder="Name" name="name" style="float:left; width:20%;margin-top:20px;">-->
               <button type="submit" class="btn btn-primary" style="float:right; width:10%; margin-top:20px; margin-right:20px;">Submit</button>
               <br/><br/><br/><br/><br/>
<div class="container">
    <div class="row clearfix">
		<div class="col-md-12 column">
<button type="button" class='addmore' value="Add Row" onclick="addRow('dataTable')" >+Add Row</button>
    <button type="button" class='delete' style='margin-left:200px;' value="Delete Row" onclick="deleteRow('dataTable')" >-Remove Row</button>
    <table id="dataTable" width="350px" border="1">
        <tr>
            <td><input type="checkbox" name="chk"/></td>
            <?php
				 while ($row1 = mysql_fetch_array($gentquery)) {
					  //echo "<tr>";
					  echo '<td><input type="text" maxlength="2" size="2" class="input-small" name="quantity'.$row1[2].'" /></td>';
					  ?>
                             <?php
			echo '<td>';		
					echo "<select id=items name=items value=''>Items</option>"; // list box select command
					echo  "<option>---Select Items--</option>";
				 while ($row = mysql_fetch_array($gentquery)) {
					   ?>
					    <option value="<?php echo $row[2];?>"><?php echo $row[2];?></option>				  
<?php }?> 
 </select>
            </td>
	<?
	echo '<td>';
	echo '<td><select class="" name="dryclean'.$row[2].'"><option value="Dryclean">Dryclean</option><option value="Laundry">Laundry</option><option value="Ironing">Ironing</option></select></td>';
        </tr>
    </table>
<p>
</form>
</div>
<?php
if(isset($_POST['submit'])){
print_r($_POST);
}
?>
		</div>
	</div>
	</div>
	</div>
</div><!-- end container -->
</body>
<?php
				 }
?>

-- phpMyAdmin SQL Dump
-- version 4.2.7.1
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Dec 03, 2015 at 06:26 PM
-- Server version: 5.5.39
-- PHP Version: 5.4.31
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `lms`
--
-- --------------------------------------------------------
--
-- Table structure for table `clothes`
--
CREATE TABLE IF NOT EXISTS `clothes` (
`id` int(11) NOT NULL,
  `category_id` int(11) NOT NULL,
  `name` varchar(60) NOT NULL,
  `laundry_rate` double NOT NULL,
  `dryclean_rate` double NOT NULL,
  `ironing_rate` double NOT NULL
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=95 ;
--
-- Dumping data for table `clothes`
--
INSERT INTO `clothes` (`id`, `category_id`, `name`, `laundry_rate`, `dryclean_rate`, `ironing_rate`) VALUES
(1, 2, 'Skirt/Trouser', 1300, 1400, 700),
(2, 2, 'Skirt/TrouserSuit3', 1500, 1600, 800),
(3, 2, 'Dress-Suits', 700, 800, 700),
(4, 1, 'Trousers-Jeans', 400, 500, 250),
(5, 1, 'Shirt', 500, 600, 300),
(6, 2, 'T-Shirt', 300, 400, 200),
(7, 1, 'Trousers -Silk/Linen', 500, 600, 300),
(8, 1, 'Jackets-Silk/Linen', 900, 1000, 500),
(9, 1, 'Waist-Coats', 400, 500, 200),
(10, 1, 'Jackets-Leather', 1400, 1500, 750),
(11, 1, 'Jackets-Jeans', 600, 700, 350),
(12, 1, 'Long-Coats', 1400, 1500, 750),
(13, 1, 'Safari/Without-Line', 1100, 1200, 600),
(14, 1, 'Trousers', 500, 600, 250),
(15, 1, 'Suit/Safari-2pcs', 1700, 1800, 900),
(16, 1, 'Suit-3pcs', 1800, 2000, 1000),
(17, 1, 'Shorts/Knickers', 300, 400, 200),
(18, 1, 'SportsWear-CPLT', 1100, 1200, 600),
(19, 1, 'Singlet', 200, 300, 150),
(20, 1, 'Pyjamas', 400, 500, 250),
(21, 1, 'Boxer/Short', 300, 400, 200),
(22, 1, 'French/Military-Suit', 1500, 1600, 800),
(23, 1, 'Lawyer/Graduatn-Robe', 1800, 2000, 1000),
(24, 1, 'Canvas/Sport-Shoes', 500, 500, 250),
(25, 1, 'Socks-Pair', 100, 100, 50),
(26, 1, 'Caps/Hats', 700, 800, 250),
(27, 1, 'Sweater', 500, 600, 300),
(28, 1, 'Jalabiya', 500, 600, 300),
(29, 1, 'Complete-National', 1800, 2000, 1000),
(30, 1, 'Kaftan', 400, 500, 500),
(31, 1, 'Kaftans-Silk/Senegal', 1000, 1200, 650),
(32, 1, 'Buba/Sokoto', 500, 600, 450),
(33, 1, 'Agbada-Only', 800, 1000, 500),
(34, 2, 'Pleated-Skirt(Suit)', 1800, 2000, 1000),
(35, 2, 'Dresses', 800, 900, 450),
(36, 2, 'Trouser', 400, 500, 250),
(37, 2, 'Camisole', 200, 300, 150),
(38, 2, 'Shirt/Blouse', 300, 400, 500),
(39, 2, 'Jacket', 800, 900, 500),
(40, 2, 'Skirts(Short)', 400, 500, 250),
(41, 2, 'Gown(Long/Short)', 800, 1000, 500),
(42, 2, 'Evening-Gown(L/S)', 800, 1000, 500),
(43, 2, 'Special-Lace', 1800, 2000, 1000),
(45, 1, 'T-Shirts', 200, 400, 200),
(46, 1, 'Ties', 300, 300, 150),
(47, 2, 'Beaded/Sequins-Eveng', 1800, 2000, 1000),
(48, 2, 'Waist-Coat', 300, 400, 200),
(49, 2, 'Scarf-Small', 300, 400, 200),
(50, 2, 'Head-Tie', 900, 1000, 525),
(51, 2, 'Gele', 1400, 1500, 200),
(52, 2, 'Knickers/Shorts', 300, 400, 200),
(53, 2, 'Wedding-Gown(Small)', 7500, 8000, 4000),
(54, 2, 'Wedding-Gown(Big)', 9000, 10000, 5000),
(55, 2, 'India-Saree(Complete)', 1800, 2000, 1000),
(56, 2, 'India-Saree(Half)', 1100, 1200, 600),
(57, 2, 'Kaftaan', 800, 900, 450),
(58, 2, 'Wrapper/Buba/Headtie', 900, 1050, 525),
(59, 2, 'Buba', 800, 900, 450),
(60, 2, 'Pant', 300, 400, 200),
(61, 2, 'Skirt/Blouse', 900, 1000, 500),
(62, 2, 'National-Blouse', 500, 600, 300),
(63, 3, 'Bed-sheet', 600, 700, 350),
(64, 3, 'Blanket(Single-Bed)', 1300, 1500, 750),
(65, 3, 'Blanket(Double-Bed)', 1800, 2000, 1000),
(66, 3, 'Mattress-Cover(Single)', 900, 1000, 500),
(67, 3, 'Mattress-Cover(Double)', 1100, 1200, 600),
(68, 3, 'Flat/Fitted-Sht(Single)', 900, 1000, 500),
(69, 3, 'Flat/Fitted-Sheet(Double)', 1400, 1500, 750),
(70, 3, 'Sheet-With-Skirting(Single)', 900, 1000, 500),
(71, 3, 'Sheet-With-Skirting(Double)', 1400, 1500, 750),
(72, 3, 'Duvet(Single-Bed)', 1000, 1200, 600),
(73, 3, 'Duvet(Double-Bed)', 1300, 1500, 750),
(74, 3, 'Duvet-Cover(Single-Bed)', 900, 1000, 500),
(75, 3, 'Duvet-Cover(Double-Bed)', 900, 1000, 500),
(76, 3, 'Quilt(Single-Bed)', 900, 1000, 500),
(77, 3, 'Quilt(Double-Bed)', 1300, 1500, 750),
(78, 3, 'Pillow', 900, 1000, 500),
(79, 3, 'Throw/Collar-Pillow', 1200, 1300, 650),
(80, 3, 'Pillow-Case', 100, 200, 100),
(81, 3, 'Throw/Collar-Pillow-Cover', 200, 400, 650),
(82, 3, 'Face-Towels', 50, 100, 50),
(83, 3, 'Hand-Towels', 100, 200, 100),
(84, 3, 'Bath-Towels', 300, 400, 200),
(85, 3, 'Bath Towels (Large)', 325, 650, 300),
(86, 3, 'Bath-Towels(X-Large)', 1300, 1500, 750),
(87, 3, 'Bathroom-Floor(Rugs)', 1800, 2000, 1000),
(88, 3, 'Bath-Robes', 500, 600, 300),
(89, 3, 'Curtains-(Small Singles)', 700, 800, 400),
(90, 3, 'Curtains-(Big Doubles)', 1100, 1200, 600),
(91, 3, 'Foot-Mats', 300, 400, 200),
(92, 3, 'Linen', 300, 400, 200),
(93, 3, 'Table-Covers-(Cotton)-SM', 700, 800, 300),
(94, 3, 'Table-Covers-(Cotton)-LG', 900, 1000, 400);
--
-- Indexes for dumped tables
--
--
-- Indexes for table `clothes`
--
ALTER TABLE `clothes`
 ADD PRIMARY KEY (`id`), ADD UNIQUE KEY `id_UNIQUE` (`id`), ADD UNIQUE KEY `name_UNIQUE` (`name`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `clothes`
--
ALTER TABLE `clothes`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=95;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;