Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7417785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:45:55+00:00 2026-05-29T07:45:55+00:00

I have a table form which contains a part where the rows can be

  • 0

I have a table form which contains a part where the rows can be added dynamically by clicking on add button. As usual, why I am coming here is having trouble in adding those values in the added rows into database. I mean, the values on the dynamically added rows are not being saved into the database, only the values of the first row is being added.

This is the script:

EDIT:

<script language="Javascript">
var i=1;
function addRowToTable()
{


 i++;
  m.r.value = i;
  var tbl = document.getElementById('table');
  var lastRow = tbl.rows.length;
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);

  var cellLeft = row.insertCell(0);
  var textNode = document.createTextNode(iteration);
  cellLeft.appendChild(textNode);

  var cellRightSel1 = row.insertCell(1);
  var sel = document.createElement('select');
  sel.name = 'name' + iteration;
  sel.setAttribute("onchange", "choosec(this);");    
  var item = new Option("","");
  sel.options[sel.length] = item;
    <?
    while($data = mysql_fetch_array($result)){                                    
    ?>
  var item = new Option("<?=$data["Name"];?>","<?=$data["ID"];?>");
  sel.options[sel.length] = item;
  <? } ?>
  cellRightSel1.appendChild(sel);

  var cellRightSel2 = row.insertCell(2);
  var sel = document.createElement('select');
  sel.name = 'class' + iteration;
  sel.setAttribute("onchange", "choosepoint(this);");    
  var item = new Option ("","");
  sel.options[sel.length] = item;
    <?
    while($data = mysql_fetch_array($result_sub)){                                    
    ?>
  var item = new Option("<?=$data["Class"];?>","<?=$data["ID"];?>");
  sel.options[sel.length] = item;
  <? } ?>
  cellRightSel2.appendChild(sel);

  var cellRight = row.insertCell(3);
  var div = document.createElement('div');
  div.id = 'point' + iteration;
  cellRight.appendChild(div);
}
    </script>

<form id="m" name="m" method="POST" action="submit.php">
<input type="hidden" name="menu_id" value="<?=$menu_id;?>">
<input type="hidden" name="r" id="r">
<table align="center" class="table">
    <tr>
    <tr>
        <td class="tablesubtitle">Adjustment</td>
        <td class="tablesubtitle"><input type="text" name="adjustment" size="2"></td>
        </td>
    </tr>
    <tr>
        <td class="tablesubtitle">Component</td>
        <td class="tablesubtitle">
        <table id="table">
    <tr>
        <td>No</td>
        <td>Name</td>
        <td>Class</td>
        <td>Point</td>
        <td>Action</td>
    </tr>
    <tr>
            <td>1</td>
        <td><select name="name">
            <option value="#">&nbsp;</option>
            <?php
                    opendb();
                $query = "SELECT * FROM student";
                $result = mysql_query($query);
                while($data = mysql_fetch_array($result)){
                    $ID = $data['ID'];
                    $Name = $data['Name'];
                    echo "<option value='$ID'>$Name</option>";
                }
            ?>
             </select>
        </td>
        <td><select name='class' onchange="choosepoint(this);">
            <option value="#">&nbsp;</option>
            <?php
                    opendb();
                $query = "SELECT * FROM student2";
                $result = mysql_query($query);
                while($data = mysql_fetch_array($result)){
                        $ID1 = $data['ID'];
                    $class = $data['Class'];
                    echo "<option value='$ID'>$class</option>";
                }
            ?>
            </select>
        </td>
        <td>
                <div id="point" name="point"></div>
            </td>
            <td><input type="button" value=" + " onClick="addRowToTable();"> | <input type="button" value=" - " onClick="removeRowFromTable();"></td>
    </tr>
</table>    
        </td>
        <tr>
        <td></td>
        <td align="center"><input type="submit" value="Submit"></td>
        </tr>
    </tr>
</table>
</form>

Submit.php

<?php
include ("c/config.php");
include ("c/db.php");

opendb();
$query1 = "select * from student where ID='$name'";
$result1 = querydb($query1);
$data = mysql_fetch_array($result1);
    $adjustment = $data['adjustment'];

$num = $_POST['r'];
//echo $num;
for($i=0; $i<=$num; $i++){
if(isset($_REQUEST['name$i'])){
    $name = $_REQUEST['name$i'];
}
if(isset($_REQUEST['class$i'])){
    $class = $_REQUEST['class$i'];
}
if(isset($_REQUEST['point$i'])){
    $point = $_REQUEST['point$i'];
}

$query2 = "INSERT INTO student3
            VALUES('$adjustment','$name','$class','$point')";
$result2 = querydb($query2);
}
closedb();
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:45:55+00:00Added an answer on May 29, 2026 at 7:45 am

    I’ve found out the problems.
    This is my latest code:

    var i=0;
    function addRowToTable()
    {
     i++;
      m.r.value = i;
      var tbl = document.getElementById('table');
      var lastRow = tbl.rows.length;
      var iteration = lastRow - 1;
      var row = tbl.insertRow(lastRow);
    
      var cellLeft = row.insertCell(0);
      var textNode = document.createTextNode(iteration);
      cellLeft.appendChild(textNode);
    
      var cellRightSel1 = row.insertCell(1);
      var sel = document.createElement('select');
      sel.name = 'name' + iteration;
      sel.setAttribute("onchange", "choosec(this);");    
      var item = new Option("","");
      sel.options[sel.length] = item;
        <?
        while($data = mysql_fetch_array($result)){                                    
        ?>
      var item = new Option("<?=$data["Name"];?>","<?=$data["ID"];?>");
      sel.options[sel.length] = item;
      <? } ?>
      cellRightSel1.appendChild(sel);
    
      var cellRightSel2 = row.insertCell(2);
      var sel = document.createElement('select');
      sel.name = 'class' + iteration;
      sel.setAttribute("onchange", "choosepoint(this);");    
      var item = new Option ("","");
      sel.options[sel.length] = item;
        <?
        while($data = mysql_fetch_array($result_sub)){                                    
        ?>
      var item = new Option("<?=$data["Class"];?>","<?=$data["ID"];?>");
      sel.options[sel.length] = item;
      <? } ?>
      cellRightSel2.appendChild(sel);
    
      var cellRight = row.insertCell(3);
      var div = document.createElement('div');
      div.id = 'point' + iteration;
      cellRight.appendChild(div);
    }
        </script>
    
    <form id="m" name="m" method="POST" action="submit.php">
    <input type="hidden" name="menu_id" value="<?=$menu_id;?>">
    <input type="hidden" name="r" id="r">
    <table align="center" class="table">
        <tr>
        <tr>
            <td class="tablesubtitle">Adjustment</td>
            <td class="tablesubtitle"><input type="text" name="adjustment" size="2"></td>
            </td>
        </tr>
        <tr>
            <td class="tablesubtitle">Component</td>
            <td class="tablesubtitle">
            <table id="table">
        <tr>
            <td>No</td>
            <td>Name</td>
            <td>Class</td>
            <td>Point</td>
            <td>Action</td>
        </tr>
        <tr>
                <td>1</td>
            <td><select name="name">
                <option value="#">&nbsp;</option>
                <?php
                        opendb();
                    $query = "SELECT * FROM student";
                    $result = mysql_query($query);
                    while($data = mysql_fetch_array($result)){
                        $ID = $data['ID'];
                        $Name = $data['Name'];
                        echo "<option value='$ID'>$Name</option>";
                    }
                ?>
                 </select>
            </td>
            <td><select name='class' onchange="choosepoint(this);">
                <option value="#">&nbsp;</option>
                <?php
                        opendb();
                    $query = "SELECT * FROM student2";
                    $result = mysql_query($query);
                    while($data = mysql_fetch_array($result)){
                            $ID1 = $data['ID'];
                        $class = $data['Class'];
                        echo "<option value='$ID'>$class</option>";
                    }
                ?>
                </select>
            </td>
            <td>
                    <div id="point" name="point"></div>
                </td>
                <td><input type="button" value=" + " onClick="addRowToTable();"> | <input type="button" value=" - " onClick="removeRowFromTable();"></td>
        </tr>
    </table>    
            </td>
            <tr>
            <td></td>
            <td align="center"><input type="submit" value="Submit"></td>
            </tr>
        </tr>
    </table>
    </form>
    
    <?php
    include ("c/config.php");
    include ("c/db.php");
    
    opendb();
    $query1 = "select * from student where ID='$name'";
    $result1 = querydb($query1);
    $data = mysql_fetch_array($result1);
        $adjustment = $data['adjustment'];
    
    $num = $_POST['r'];
    //echo $num;
    for($i=0;$i<=$num;$i++){
    if(isset($_REQUEST['name$i'])){$name = $_REQUEST['name$i'];}
    if(isset($_REQUEST['class$i'])){$class = $_REQUEST['class$i'];}
    if(isset($_REQUEST['point$i'])){$point = $_REQUEST['point$i'];}
    
    $query2 = "INSERT INTO student3
                VALUES('$adjustment','$name','$class','$point')";
    $result2 = querydb($query2);
    }
    closedb();
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form(table view) which contains textfields and textview as subviews,I need to
I have a simple data table which contains dynamic form text fields. Each field
I have a form into which the user can add more fields to fill
I have a Jquery toggle which contains an entry form to a MySQL table.
I have a div inside of a table which is inside of a form
I have a table (in a form) populated with radio buttons (with a button
I have a table for a contact form and this table contains another table
I have a table body that grabs it's rows (and form fields) via AJAX
I have a table with multiple rows. Each row is a form. I want
I have a form that searches all rows in a single table (TServices) that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.