i have some dynamic rows, when i submit a single row submit into my database. how can i insert my dynamic all rows into database by submit?
Code:
entry_history.php (page) <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <?php include("sql_conn.php");?> <style> body{background-color:#F4FDDB;} .table{ width:100%; border:groove; border-color:#FFFFFF; background-color:#E8F0EE; } th{ font-style:italic; color:#999999; } </style> <SCRIPT language="javascript"> function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; for(var i=0; i<colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[0].cells[i].innerHTML; switch(newcell.childNodes[0].type) { case "text": newcell.childNodes[0].value = ""; break; case "checkbox": newcell.childNodes[0].checked = false; break; case "select-one": newcell.childNodes[0].selectedIndex = 0; break; }}} function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { if(rowCount <= 1) { alert("Cannot delete all the rows."); break; } table.deleteRow(i); rowCount--; i--; }} }catch(e) { alert(e); }} </SCRIPT> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> </HEAD> <BODY> <header><ul><tr><li><a href="https://bytes.com/submit/mediasourcebd_reza/home.php">Home</a></li></tr></ul></header> <br /> <form action="action_entry_history.php" method="post" name="" id=""> <table class="table" > <tr> <th align="right">Title</th> <th align="right">Start Time</th> <th align="right">End Time</th> <th align="right">Program</th> <th align="center">Peak/Off Peak</th> <th align="left">Sub Brand</th> <th align="left">Sponsor</th> <th align="left">Product</th> </tr> </table> <table id="dataTable" border="0" class="table"> <tr> <td><INPUT type="checkbox" name="chk[]"/></td> <td><input type="text" name="title[]"/></td> <td><input type="time" name="start_time[]"></td> <td><input type="time" name="end_time[]"></td> <td><?php $sql = "SELECT program_name FROM program"; $result = mysql_query($sql); echo "<select name='program_name[]' >"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['program_name'] ."'>" . $row['program_name'] ."</option>"; } echo "</select>"; ?></td> <td><select name="peak_offpeak[]"><option>Peak</option><option>0ff_Peak</option></select></td> <td><?php $sql = "SELECT sub_brand_name FROM sub_brand"; $result = mysql_query($sql); echo "<select name='sub_brand_name[]' >"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['sub_brand_name'] ."'>" . $row['sub_brand_name'] ."</option>"; } echo "</select>"; ?></td> <td><input type="text" name="sponsor[]"/></td> <td><?php $sql = "SELECT product_name FROM product"; $result = mysql_query($sql); echo "<select name='product_name[]' >"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['product_name'] ."'>" . $row['product_name'] ."</option>"; } echo "</select>"; ?></td> </tr> </table> <table class="table"><th colspan="13">End</th></table> <table><th><INPUT type="button" value="Add Row" onclick="addRow('dataTable')" /> <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" /> <input type="submit" value="Save" /> </table> </form> ************************ action_entry_history.php (page) <?php include("sql_conn.php"); $title = $_POST['title'][$i]; for ($i = 0; $i < count($_POST['title']); $i++) { $title = $_POST['title'][$i]; $start_time = $_POST['start_time'][$i]; $end_time = $_POST['end_time'][$i]; $duration = $_POST['duration'][$i]; $peak_offpeak = $_POST['peak_offpeak'][$i]; $program_name = $_POST['program_name'][$i]; $sub_brand_name = $_POST['sub_brand_name'][$i]; $sponsor = $_POST['sponsor'][$i]; $product_name = $_POST['product_name'][$i]; } $que = "insert into entry_history(date,channel_name,title,start_time,end_time,duration,peak_offpeak,program_name,sub_brand_name,sponsor,product_name) values('$date','$channel_name','$title','$start_time','$end_time','$duration','$peak_offpeak','$program_name','$sub_brand_name','$sponsor','$product_name')"; if(mysql_query($que)) { header('Location:entry_history.php'); } echo "data has been inserted into database"; echo $que; exit; mysql_close($conn); ?>
Comment