Insert add row feature in PHP form and linking it to the database -
how can include add row feature in php form , insert additionally added rows database? havetried using html code button insert additional rows not work. need use javascript?? please me html code. row not added after hitting add button.
<?php session_start(); ?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <script language="javascript" type="text/javascript"> var i=1; function addrow() { var tbl = document.getelementbyid('table2'); var lastrow = tbl.rows.length; var iteration = lastrow - 1; var row = tbl.insertrow(lastrow); var firstcell = row.insertcell(0); var el = document.createelement('input'); el.type = 'text'; el.name = 'activityname_' + i; el.id = 'activityname_' + i; firstcell.appendchild(el); var secondcell = row.insertcell(1); var el2 = document.createelement('input'); el2.type = 'text'; el2.name = 'unit_' + i; el2.id = 'unit_' + i; secondcell.appendchild(el2); var thirdcell = row.insertcell(2); var el3 = document.createelement('input'); el3.type = 'text'; el3.name = 'weightage_' + i; el3.id = 'weightage_' + i; thirdcell.appendchild(el3); var thirdcell = row.insertcell(3); var el4 = document.createelement('input'); el4.type = 'text'; el4.name = 'per100_' + i; el4.id = 'per100_' + i; fourthcell.appendchild(el4); var thirdcell = row.insertcell(4); var el5 = document.createelement('input'); el5.type = 'text'; el5.name = 'per75_' + i; el5.id = 'per75_' + i; fifthcell.appendchild(el5); var thirdcell = row.insertcell(5); var el6 = document.createelement('input'); el6.type = 'text'; el6.name = 'per50_' + i; el6.id = 'per50_' + i; sixthcell.appendchild(el6); var thirdcell = row.insertcell(6); var el7 = document.createelement('input'); el7.type = 'text'; el7.name = 'per75_' + i; el7.id = 'per75_' + i; seventhcell.appendchild(el7); // alert(i); i++; frm.h.value=i; // alert(i); } </script> <?php error_reporting(0); include ('includes/workplan_func.php'); ?> <link rel="stylesheet" type="text/css" href="css/mystyle.css" /> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title> workplan detail form </title> </head> <body> <div id="wrapper"> <div id="header"> <img src="images/logo.jpg" width="305" height="108" /> </div> <div id="box"> <ul> <li><a href="workplan.php">workplan detail</a></li> <li><a href="workprogress.php">workplan progress</a></li> <li><a href="pbis_form.php">pbis</a></li> <li><a href="logout.php">logout</a></li> </ul> </div> <div id="rightcol"> <div id="content" align="center"> <h1 align="center">workplan detail form</h1> <div id="table1" class="container" align="left"> //<form name="frm" id="frm" action="includes/workplan_func.php" method="post"> <table width="398" height="118" border="0" align="left" > <td> <tr> <td > <p>division name:</p> </td> <td><input name="divisionname" type="text" /></td> </tr> <tr> <td><p>division chief: </p></td> <td> <input type="text" name="divisionchief" /></td> </tr> <tr> <td><p> period: </p> </td> <td> <input type="text" name="period" /></td> </tr> <tr> <td><p> month:</p> </td> <td> <input type="month" name="month" /> </td> </tr> </table> </td> </table> </div> <div id="table2"> <table border="1" align="center" cellpadding="1" cellspacing="1"> <tr> <td rowspan="2" align="center"> sn </td> <td rowspan="2" align="center"> activity name </td> <td rowspan="2" align="center" > unit </td> <td rowspan="2" align="center"> weightage </td> <td colspan="4" align="center"> performance indicators(percentage) </td> <tr> <td align="center">100 </td> <td align="center"> 75</td> <td align="center"> 50 </td> <td align="center"> <50 </td> </tr> <form name="frm" id="frm" action="includes/workplan_func.php" method="post"> <table border="1" align="center" cellpadding="1" cellspacing="1" id="table2"> <tr> <td width:50px > </td> <td> <input type="text" name="activityname_0" id="activityname_0" style="width:130px"/> </td> <td> <input type="text" name="unit_0" id="unit_0" style="width:50px" /> </td> <td> <input type="text" name="weightage_0" id="weightage_0" style="width:130px" /> </td> <td> <input type="text" name="per100_0" id="per100_0" style="width:50px" /> </td> <td> <input type="text" name="per75_0" id="per75_0" style="width:50px" /> </td> <td> <input type="text" name="per50_0" ="per50_0" style="width:50px" /> </td> <td> <input type="text" name="perless50_0" id="perless50_0" style="width:50px" /> </td> </tr> </table> </div> <div id="button"> <div align="center"> <input type="button" value="add" onclick="addrow();" /> <input name="submit" type="submit" value="submit" /> </div> </div> </div> <label> <input name="h" type="hidden" id="h" value="0" /> </label> </form> </body> </html>
if looking add more 1 value without having iterate on possible outputs again , again statement such following may assuming using mysql:
insert your_table (value1,value2,value3) values (v1,v2,v3),(v1,v2,v3),(etc...)
if looking add form fields html want javascript/jquery solution gives visual appeal looking for.
you need create code dynamically forms string in place of (v1,v2,v3),(v1,v2,v3),(etc...)
can simple foreach loop.
hope helps out little.
Comments
Post a Comment