Hello to experts out there, I have created a dynamic web form where by user may add and remove table rows. However, I met problems collecting the data from the dynamic created rows. I have a incrementable count id, 2 txt box for calculation, 2dropdownlist, 1 static with onchange action, 1 with mysql dataset, 3 buttons of add, remove and continue. The forms can be dynamically created but the calculation, onchange, n sql doesn't work which i know why but i couldn't come out with a good coding. The continue button is for me to session the datas to the nxt page for confirmation. Anyone available to help.. <?php session_start(); mysql_connect("localhost", "root", "user") or die("Error connecting to database!"); mysql_select_db("mrequest") or die("Error connecting to database table!"); $query="SELECT * FROM `user` WHERE role='director' OR role='approver'"; $result = mysql_query($query); $query2 ="SELECT * FROM `user` WHERE username='".$_SESSION["valid_user"]."' LIMIT 1"; $result2 = mysql_query($query2); $nt2=mysql_fetch_array($result2); $_SESSION['itemta1'] = $_POST['itemta1']; $_SESSION['itype1'] = $_POST['itype1']; $_SESSION['qty1'] = $_POST['qty1']; $_SESSION['price1'] = $_POST['price1']; $_SESSION['gst1'] = $_POST['gst1']; $_SESSION['purpose1'] = $_POST['purpose1']; $_SESSION['remarksta1'] = $_POST['remarksta1']; $_SESSION['approver1'] = $nt3[lastName].' '.$nt3[surName]; $_SESSION['tprice1'] = $_POST['tprice1']; $_SESSION['purposeta1'] = $_POST['purposeta1']; $_SESSION['requester'] = $nt2[lastName].' '.$nt2[surName]; $_SESSION['rowCount1'] = $_POST['rowCount1']; ?> <html> <head> <title>Material Request Form</title> <script language="JavaScript" type="text/javascript"> var count = 1; function insRow() { var x=document.getElementById('request').insertRow(-1); var a=x.insertCell(0); var b=x.insertCell(1); var c=x.insertCell(2); var d=x.insertCell(3); var e=x.insertCell(4); var f=x.insertCell(5); var g=x.insertCell(6); var h=x.insertCell(7); var i=x.insertCell(8); var j=x.insertCell(9); count = count+1; var itemtac = "itemta"+count; var itypec = "itypec"+count; var qtyc = "qtyc"+count; var pricec = "pricec"+count; var gstc = "gstc"+count; var purposec = "purposec"+count; var purposetac = "purposetac"+count; var remarkstac = "remarksta"+count; var approverc = "approverc"+count; var tpricec = "tpricec"+count; var rowCountc = "rowCountc"+count; a.innerHTML='<label for="rc" name='+rowCountc+'>'+count+'</label>'; b.innerHTML='<textarea rows="3" name=' +itemtac+' cols="20" style="font-size:12"></textarea>'; c.innerHTML='<input type="radio" name=' +itypec+' value="Physical" checked>Physical<br><input type="radio" name=' +itypec+ ' value="Non Physical">Non-Physical'; d.innerHTML='<input type="text" name='+qtyc+' size="4" style="font-size:12">'; e.innerHTML='$<input type="text" name='+pricec+' size="6" style="font-size:12">'; f.innerHTML='<input type="radio" name='+gstc+' value="GST Inclusive">GST Inclusive<br><input type="radio" name='+gstc+' value="GST Exclusive" checked>GST Exclusive'; g.innerHTML='$<input type="text" name='+tpricec+' size="6" style="font-size:12">'; h.innerHTML='<select name='+purposec+' style="font-size:12"><option value=""></option><option value="Office Use">Office Use</option><option value="ncs">Non-chargeable Servicing</option><option value="cs">Chargeable Servicing</option><option value="st">Sales To</option><option value="others">Others</option></select><br><textarea rows="2" name='+purposetac+' cols="19" style="font-size:12"></textarea>'; i.innerHTML='<textarea rows="3" name='+remarkstac+' cols="20" style="font-size:12"></textarea>'; j.innerHTML='<select name='+approverc+' style="font-size:12"><option value=""></option><option value="Andy Soo">Andy Soo</option><option value="Simon Low">Simon Low</option></select>'; } function delRow(){ var x=document.getElementById('request'); var lastRow = x.rows.length if (lastRow>2) { x.deleteRow(count); count = count - 1; } } function Calculate(){ if (document.getElementById('gstyes').checked){ myform.tprice1.value = myform.qty1.value * myform.price1.value; } else myform.tprice1.value = myform.qty1.value * myform.price1.value * 1.07; } function purpose(){ if(myform.purpose1.value=="Office Use"){myform.purposeta1.enabled=="false";} else if(myform.purpose1.value=="Non-chargeable Servicing"){myform.purposeta1.value="Case ID / Project";} else if(myform.purpose1.value=="Chargeable Servicing"){myform.purposeta1.value="Case ID / Project";} else if(myform.purpose1.value=="Sales To"){myform.purposeta1.value="Company / Customer Name";} else if(myform.purpose1.value=="Others"){myform.purposeta1.value="Please Specify";} } </script> </head> <?php echo "<html>"; echo "<body>"; echo "<table width='1150px' border='0'>"; echo "<tr><td width='300px'>"; echo "Sign in as: <b>" .$nt2[lastName].' '.$nt2[surName]; echo "</td>"; echo "<td width='850px'>"; echo "</b></td><tr><td width='300px'>Date logged in: <b>" . date("m/d/Y", $_SESSION["valid_time"]); if (!$_SESSION["valid_user"]) { Header("Location: index.php"); } else{ if ($_SESSION["valid_user"]=="simonlow"){ echo "</b><td width='850px' align='right'><a href ='members.php' STYLE='text-decoration:none'>home |</a><a href='pending.php' STYLE='text-decoration:none'> pending |</a><a href='logout.php' STYLE='text-decoration:none'> logout |</a></td>"; } else { echo "</b><td width='850px' align='right'><a href ='members.php' STYLE='text-decoration:none'>home |</a><a href='logout.php' STYLE='text-decoration:none'> logout</a><td>"; } } echo "</tr></table><br>"; ?> <form name ="myform" action="continue.php" method="post"> <input type="button" onclick="insRow()" value="Add"> <input type="button" onclick="delRow()" value="Remove"> <input type="submit" value="Continue"><br><br> <table bordercolor="burlywood" border="3" id="request" style="font-size:12" width="1150px"> <tr bgcolor="cornsilk" style="font-style:italic"> <td>P/N</td> <td>Item Description</td> <td>Item Type</td> <td>Quantity</td> <td>Unit Price</td> <td>GST</td> <td>Total Price</td> <td>Purpose</td> <td>Remark</td> <td>Approver</td> </tr> <tr> <td><label for="rc" name="rowCount1">1</label></td> <td> <textarea rows="3" name="itemta1" cols="20" style="font-size:12"></textarea> </td> <td> <input type="radio" name="itype1" value="Physical" checked>Physical<br> <input type="radio" name="itype1" value="Non Physical">Non-Physical </td> <td><input type="text" name="qty1" onBlur="Calculate()" size="4" style="font-size:12"></td> <td> $<input type="text" name="price1" onBlur="Calculate()" size="6" style="font-size:12"> </td> <td> <input type="radio" name="gst1" id="gstyes" value="Inclusive" onClick="Calculate()">GST Inclusive<br> <input type="radio" name="gst1" id="gstno" value="Exclusive" Checked onClick="Calculate()">GST Exclusive </td> <td> $<input type="text" name="tprice1" size="6" style="font-size:12"> </td> <td> <select name="purpose1" onChange="purpose()" style="font-size:12"> <option value=""></option> <option value="Office Use">Office Use</option> <option value="Non-chargeable Servicing">Non-chargeable Servicing</option> <option value="Chargeable Servicing">Chargeable Servicing</option> <option value="Sales To">Sales To</option> <option value="Others">Others</option> </select><br> <textarea rows="2" name="purposeta1" cols="19" style="font-size:12"></textarea> </td> <td> <textarea rows="3" cols="20" name="remarksta1" style="font-size:12"></textarea> </td> <td> <select name='approver1' style='font-size:12'> <option value=''></option> <?PHP while($nt=mysql_fetch_array($result)){ echo "<option value='$nt[username]'>$nt[lastName] $nt[surName]</option>"; } ?> </select> </td> </tr> </table> </form> </select> </body> </html> PHP:
with different ids the dynamic table should work. maybe it is some problem in passing data to the database. you can make another script without database connection just to see if you can catch the data from the dynamic rows to the php by the session variables (just print them in the php script, for example). this way you will see if it is a problem with the database or the pass of variables.