Hello Friends,

I have created 2 page
1)add
2)edit

In edit page i am showing the results what users have entered in add page. The add and edit page will have minimum 4 rows. Suppose the users have enter only 2 rows in add page than in the edit page i have created a loop which will show up total of 4 rows. I have one more feature in the edit page, when the user click on add more one more row will be added.

My question is how to update the information when they click on submit button. And also how to insert the data which they enter in the new row.

My edit page code is

PHP Code:
<html>
<head><body bgcolor='#F0F0F0'>
<script lang="javascript"> 

function subit(i) { 
 if (i == 1) { 
  document.form.action = 'edit_save.php?i=1'; 
 } else if (i == 2) { 
  document.form.action = 'assign_grade_industry_submit.php?i=2'; 
 } 
 document.form.submit(); 


</script>
<script type="text/javascript">

function debug_ie () 
{  
var body = document.getElementsByTagName('body').item(0);  
var debug = document.createElement('textarea');  
debug.setAttribute( 'rows', 30 );  
debug.setAttribute( 'cols', 60 );  
debug.setAttribute( 'wrap', 'off' );  
debug.value = document.getElementsByTagName('html').item(0).innerHTML;  
body.appendChild( document.createElement('br') );  
body.appendChild( debug );
}

function delete_row ( target ) {
  do {
    if ( target.nodeName.toUpperCase() == 'TR' ) {
      target.parentNode.removeChild(target);
      break;
    }
  } while ( target = target.parentNode );
}

function add_row ( table ) {
  if( typeof document.getElementById == 'undefined' || 
    typeof document.createElement == 'undefined' ) {
    return; // Only DOM browsers
  }
  var table = document.getElementById(table) ;

  var pos = 0;
  var authors = [];
  for ( var i = 0; i < table.rows.length; i ++ ) {
    var row = table.rows.item(i);
    if ( /author/.test( row.className ) ) {
      authors.push(row);
      pos ++;
    }
  }
  
  var tr = document.createElement('tr');
  tr.setAttribute('class','author');
  
  var td1 = document.createElement('td');
  var field = document.createElement('select');
  field.setAttribute('name','local[]');
  field.setAttribute('id','local[]');
  field.options[0] = new Option('--Select--','');
  field.options[1] = new Option('Local','Local');
  field.options[2] = new Option('Central','Central');
  //field.setAttribute('value',pos); // testing purposes
  td1.appendChild(field);
  tr.appendChild(td1);

      
  var td2 = document.createElement('td');
  var field = document.createElement('textarea');
  field.setAttribute('name','duties[]');
  field.setAttribute('id','duties[]');
  //field.setAttribute('type','textarea');
  field.setAttribute('cols','25');
  field.setAttribute('rows','4');
  //field.setAttribute('value',pos); // testing purposes
  td2.appendChild(field);
  tr.appendChild(td2);
  
  var td3 = document.createElement('td');
  var field = document.createElement('textarea');
  field.setAttribute('name','skills[]');
  field.setAttribute('id','skills[]');
  //field.setAttribute('type','textarea');
  field.setAttribute('cols','25');
  field.setAttribute('rows','4');  
  //field.setAttribute('value',pos); // testing purposes
  td3.appendChild(field);
  tr.appendChild(td3);


  var td4 = document.createElement('td');
  var button = document.createElement('input');
  button.setAttribute('onclick','delete_row(this)');
  button.setAttribute('value','Delete');
  button.setAttribute('type','button');
  button.onclick = function () 

 delete_row( this );  
};
  td4.appendChild(button);
  tr.appendChild(td4);

  var next_node = authors[pos -1];
  while ( next_node = next_node.nextSibling ) {
    if ( next_node.nodeName.toUpperCase() == 'TR' ) {
      break;
    }
  }

  if ( table.tBodies.length ) {
    if ( next_node ) {
      table.tBodies[0].insertBefore( tr, next_node );
    } else {
      table.tBodies[0].appendChild( tr );
    }
  } else {
    if ( table.tBodies.length ) {
      table.insertBefore( tr, next_node );
    } else {
      table.appendChild( tr );
    }
  }
}

</script>
</head><br><br>
<body>

$query  = "SELECT test_id,member_id, local, duties, skill FROM it_survey where member_id='0' order by test_id";

$result = mysql_query($query);
$n = mysql_numrows($result);
?>
 
<form enctype="multipart/form-data" name="form"  method="post" action="edit_submit.php" name='form'>
  <table align="center" cellpadding="4" cellspacing="0" id="tblView" border="1" >
   <tr align="center">
<td valign="top">Local/Central</td>

<td>Duties</td>
<td>Skill Set</td>
<td>Action</td>
</tr>
  <?php
while($row mysql_fetch_array($resultMYSQL_ASSOC))
{
    echo 
'<tr class="author">';
    
$a=$row['local'];
    
?>
    <td>
<input type="hidden" name="id[]" value="<?php echo $row['id']; ?>" />

<select name="local[]">
  <option <? if($a == ""){ echo 'selected'; } ?>  value="">--Select--</option>
  <option <? if($a == "Local"){ echo 'selected'; } ?>  value="Local">Local</option>
  <option <? if($a == "Central"){ echo 'selected'; } ?>  value="Central">Central</option>

  </select></td>

    <?
    
echo "<td><textarea rows='4' cols='25' name='duties[]'>{$row['duties']}</textarea> </td>" .
         
"<td><textarea rows='4' cols='25' name='skills[]'>{$row['skill']}</textarea> </td>" ;
echo       
'<td><input type="button" value="Delete" onclick="delete_row(this)"></td>';
    echo 
'</tr>';

}

//Display between 0 and 4 additional rows depending on $n
for ($i 0$i < ($n); $i++) {
?>

    <tr class="author">
      <td>
        <input type="hidden" name="id[]" value="" />
        <select name="local[]">
                                <option VALUE="">--Select--
                                <option VALUE="Local">Local
                                <option VALUE="Central">Central
                                </select></td>
      <td><textarea rows="4" cols="25" name="duties[]"></textarea></td>
      <td><textarea rows="4" cols="25" name="skills[]"></textarea></td>
      <td><input type="button" value="Delete" onclick="delete_row(this)"></td>
    </tr>


<?php
}
?>

    <tr>
                                <td valign="top" colspan="4" align="center">
<input name="cmdAddMore" type="button" id="cmdAddMore" value="More" onClick="add_row('tblView')" />
<input type="Submit" name="Submit" value="Save" onClick="java_script:subit(1);">
<input type="Submit" name="Submit" value="Submit" onclick="java_script:return submit_form();">
      </td>
      
    </tr>
  </table></form>
</body>
</html>