View Single Post
  #6 (permalink)  
Old 06-04-09, 04:07 AM
love_choc love_choc is offline
New Member
 
Join Date: Jun 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
hi im trying to insert multiple records(which consists of many rows) into database..
But, only the first row is inserted meanwhile other rows do not..
can anyone please help me..
i will provide my coding here~

//this ia add.php
PHP Code:

<HTML>  
<HEAD>  
    <TITLE> Add/Remove dynamic rows in HTML table </TITLE>  
    <SCRIPT language="javascript">  
        function addRow(tableID) {   
  
            var table = document.getElementById(tableID);   
            
            var rowCount = table.rows.length;   
            var row = table.insertRow(rowCount);   
              var iteration = rowCount;
  
            var cell1 = row.insertCell(0);   
            var element1 = document.createElement("input");   
            element1.type = "checkbox";   
            cell1.appendChild(element1);
            
            <?php
                $sql_tag
"SELECT * FROM cattagdesc";
    
                
$rkd query($sql_tag);
                
$total sqlCount($row);
                
                
$loop 0;
            
?>
            
            var cell2 = row.insertCell(1);   
            var element2 = document.createElement("select");   
            
             <?php while($record fetchArray($rkd)) {   ?>
            element2.options[<?php echo $loop?>] = new Option('<?php echo $record['tagID'?>', '<?php echo $record['tagID'?>');
              <?php  
                $loop
++;
             }  
            
?>
            cell2.appendChild(element2);
  
            var cell3 = row.insertCell(2);   
            var element3 = document.createElement("input");
            element3.type = "text";
            cell3.appendChild(element3);
            
            var cell4 = row.insertCell(3);   
            var element4 = document.createElement("input");   
            element4.type = "text";   
            cell4.appendChild(element4);

            var cell5 = row.insertCell(4);   
            var element5 = document.createElement("input");   
            element5.type = "text";   
            cell5.appendChild(element5);
            
            var cell6 = row.insertCell(5);   
            var element6 = document.createElement("input");   
            element6.type = "text";   
            cell6.appendChild(element6);
  
        }   
  
        function deleteRow(tableID)
     {
          // grab the element again!
          var table = document.getElementById(tableID);  
          // grab the length!
          var lastRow = table.rows.length;
          // delete the last row if there is more than one row!
          if (lastRow > 2) table.deleteRow(lastRow - 1);
     }
  
    </SCRIPT>  
</HEAD>
<?php

    $sql_tag
"SELECT * FROM cattagdesc";
    
    
$rkd query($sql_tag);
    
$total sqlCount($row);

?>

<?php

if(isset($_POST["button"])&&$_POST["button"]=="Submit")
{
    include(
"insert.php");
    
//include("view1.php");
}
else{

?>  
<body>ADDITION FORM
<form method="post" enctype="multipart/form-data">

<TABLE id="dataTable" width="350px" border="1">  
        <tr>
            <th></th>
            <th>Tag Id</th>
            <th>IND1</th>
            <th>IND2</th>
            <th>DETAILS</th>
            <th>DESCRIPTION</th>
        </tr>
        <TR>  
            <TD><INPUT type="checkbox" name="chk"/></TD>  
            <TD>
          <select name="tagID" id="tagID">
              <option value="">&nbsp;</option>
     <?php while($record fetchArray($rkd)) 
        {   
?>
               <option value="<?php echo $record['tagID']; ?>"<?php if ($_POST['tagID'] == $record['tagID']) echo "selected" ?>><?php echo $record['tagID']; ?></option>
      <?php ?>
          </select>
    </TD> 
            <TD><INPUT type="text" name="ind1"/></TD>
            <TD><INPUT type="text" name="ind2"/></TD>
            <TD><INPUT type="text" name="detail"/></TD>
            <TD><INPUT type="text" name="name"/></TD>
        </TR>
    
<tr>
<br>
<br>
<INPUT type="button" value="Add Row" onClick="addRow('dataTable')" />  
  
    <INPUT type="button" value="Delete Row" onClick="deleteRow('dataTable')" />  
  </TABLE>
  
<br>
<input type="submit" onClick="if(check())return true; else return false;" name="button" value="Submit" />&nbsp;
<input type="reset" name="reset" value="Reset" onClick="if(confirm('Reset all data?'))return true;else return false;" />&nbsp;
<input type="button" name="cancel" value="Cancel" onClick="if(confirm('Back to View uitmlib?'))location='index1.php?page=view1';else return false;" />


</form>
<?php
}
?></body>
 
</HTML>
//this is insert.php
PHP Code:

<?php

    $sql1
"insert into catbiborgdesc(bib_name) values('')";
    
insertData($sql1,$dbName);
    
    
$sql2 "SELECT MAX(bibID) AS max_value FROM catbiborgdesc";
    
$rkd viewRecord($sql2,$dbName);
    
    
$next_bib_id $rkd->max_value;
    
    
$sql3"select tagID from cattagdesc WHERE tagID='".$_POST["tagID"]."'";
    if(
$result mysql_query($sql3,$db))
    {
        if(
mysql_num_rows($result)>0)
        {
        if (
$_POST["tagID"]=='100'){   // INSERT INTO TABLE AUTHOR
    
         
$sql4 ="insert into catauthortag(bibID,tagID,ind1,ind2,detail,name) values ($next_bib_id,'".$_POST["tagID"]."','".$_POST["ind1"]."','".$_POST["ind2"]."','".$_POST["detail"]."','".$_POST["name"]."')"
    
        
insertData($sql4,$dbName);
        
        }else if(
$_POST["tagID"]=='245'){  // INSERT INTO TABLE TITLE
    
         
$sql4 ="insert into cattitletag(bibID,tagID,ind1,ind2,detail,name) values ($next_bib_id,".$_POST["tagID"].",'".$_POST["ind1"]."','".$_POST["ind2"]."','".$_POST["detail"]."','".$_POST["name"]."')";  
     
        
insertData($sql4,$dbName);
    
        }else if(
$_POST["tagID"]=='020'){  // INSERT INTO TABLE ISBN
    
         
$sql4 ="insert into catisbntag(bibID,tagID,ind1,ind2,detail,name) values ($next_bib_id,'".$_POST["tagID"]."','".$_POST["ind1"]."','".$_POST["ind2"]."','".$_POST["detail"]."','".$_POST["name"]."')"
     
        
insertData($sql4,$dbName);
        } 
        }
    }      
            
?>

Last edited by Nico; 06-04-09 at 09:47 AM. Reason: Wrappers.
Reply With Quote