473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

dynamic rows insert into database using php

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?








Expand|Select|Wrap|Line Numbers
  1. entry_history.php    (page)
  2.  
  3.  
  4.  
  5.  
  6.  
  7. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  8. <html xmlns="http://www.w3.org/1999/xhtml">
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  11. <title>Untitled Document</title>
  12.  
  13. <?php include("sql_conn.php");?>
  14.  
  15. <style>
  16. body{background-color:#F4FDDB;}
  17. .table{
  18. width:100%;
  19.  
  20. border:groove;
  21. border-color:#FFFFFF;
  22.  
  23. background-color:#E8F0EE;
  24. }
  25. th{
  26. font-style:italic;
  27. color:#999999;
  28.  
  29. }
  30. </style>
  31.  
  32.  
  33.  
  34.  
  35.  
  36. <SCRIPT language="javascript">
  37.  
  38.                 function addRow(tableID) {
  39.                 var table = document.getElementById(tableID);
  40.  
  41.              var rowCount = table.rows.length;
  42.             var row = table.insertRow(rowCount);
  43.  
  44.             var colCount = table.rows[0].cells.length;
  45.  
  46.            for(var i=0; i<colCount; i++) {
  47.            var newcell = row.insertCell(i);
  48.            newcell.innerHTML = table.rows[0].cells[i].innerHTML;
  49.            switch(newcell.childNodes[0].type) {
  50.                     case "text":
  51.                             newcell.childNodes[0].value = "";
  52.                             break;
  53.                     case "checkbox":
  54.                             newcell.childNodes[0].checked = false;
  55.                             break;
  56.                     case "select-one":
  57.                             newcell.childNodes[0].selectedIndex = 0;
  58.                             break;
  59.  
  60.          }}}
  61.  
  62.         function deleteRow(tableID) {
  63.           try {
  64.            var table = document.getElementById(tableID);
  65.             var rowCount = table.rows.length;
  66.             for(var i=0; i<rowCount; i++) {
  67.                var row = table.rows[i];
  68.                 var chkbox = row.cells[0].childNodes[0];
  69.                 if(null != chkbox && true == chkbox.checked) {
  70.                     if(rowCount <= 1) {
  71.                         alert("Cannot delete all the rows.");
  72.                         break;
  73.                     }
  74.                     table.deleteRow(i);
  75.                     rowCount--;
  76.                     i--;
  77.                 }}
  78.             }catch(e) {
  79.                 alert(e);
  80.             }}
  81.  
  82.  
  83.  
  84.  
  85.     </SCRIPT>
  86.      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. </HEAD>
  98. <BODY>
  99. <header><ul><tr><li><a href="https://bytes.com/submit/mediasourcebd_reza/home.php">Home</a></li></tr></ul></header>
  100. <br />
  101.  
  102.  
  103.  
  104.     <form action="action_entry_history.php" method="post" name="" id="">
  105.     <table class="table" >
  106.     <tr>
  107.  
  108.         <th  align="right">Title</th>
  109.         <th  align="right">Start Time</th>
  110.         <th align="right">End Time</th>
  111.         <th  align="right">Program</th>
  112.         <th  align="center">Peak/Off Peak</th>
  113.         <th align="left">Sub Brand</th>
  114.         <th align="left">Sponsor</th>
  115.         <th align="left">Product</th>
  116.     </tr>
  117.     </table>
  118.     <table id="dataTable" border="0" class="table">
  119.             <tr>
  120.             <td><INPUT type="checkbox" name="chk[]"/></td>
  121.  
  122.             <td><input type="text" name="title[]"/></td>
  123.             <td><input type="time" name="start_time[]"></td>
  124.             <td><input type="time" name="end_time[]"></td>
  125.  
  126.  
  127.             <td><?php 
  128.                         $sql = "SELECT program_name FROM program";
  129.                         $result = mysql_query($sql);
  130.                         echo "<select name='program_name[]' >";
  131.                         while ($row = mysql_fetch_array($result)) {
  132.                         echo "<option value='" . $row['program_name'] ."'>" . $row['program_name'] ."</option>";
  133.                         }
  134.                         echo "</select>";        
  135.                         ?></td>
  136.             <td><select name="peak_offpeak[]"><option>Peak</option><option>0ff_Peak</option></select></td>
  137.             <td><?php 
  138.                         $sql = "SELECT sub_brand_name FROM sub_brand";
  139.                         $result = mysql_query($sql);
  140.                         echo "<select name='sub_brand_name[]' >";
  141.                         while ($row = mysql_fetch_array($result)) {
  142.                         echo "<option value='" . $row['sub_brand_name'] ."'>" . $row['sub_brand_name'] ."</option>";
  143.                         }
  144.                         echo "</select>";        
  145.                         ?></td>
  146.         <td><input type="text" name="sponsor[]"/></td>
  147.         <td><?php 
  148.                         $sql = "SELECT product_name FROM product";
  149.                         $result = mysql_query($sql);
  150.                         echo "<select name='product_name[]' >";
  151.                         while ($row = mysql_fetch_array($result)) {
  152.                         echo "<option value='" . $row['product_name'] ."'>" . $row['product_name'] ."</option>";
  153.                         }
  154.                         echo "</select>";        
  155.                         ?></td>
  156.             </tr>
  157.  
  158.         </table>
  159.  
  160.  
  161.     <table class="table"><th colspan="13">End</th></table>
  162.     <table><th><INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
  163. <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
  164. <input type="submit" value="Save" />
  165.  
  166. </table>
  167.  
  168.  </form>
  169.  
  170.  
  171. ************************
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180. action_entry_history.php   (page)
  181.  
  182.  
  183.  
  184.  
  185. <?php include("sql_conn.php");
  186. $title = $_POST['title'][$i];
  187. for ($i = 0; $i < count($_POST['title']); $i++) {
  188.  
  189. $title = $_POST['title'][$i];
  190. $start_time = $_POST['start_time'][$i];
  191. $end_time = $_POST['end_time'][$i];
  192. $duration = $_POST['duration'][$i];
  193. $peak_offpeak = $_POST['peak_offpeak'][$i];
  194. $program_name = $_POST['program_name'][$i];
  195. $sub_brand_name = $_POST['sub_brand_name'][$i];
  196. $sponsor = $_POST['sponsor'][$i];
  197. $product_name = $_POST['product_name'][$i];
  198.  
  199. }
  200.  
  201. $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')";
  202.  
  203.  
  204.  
  205. if(mysql_query($que))
  206. {
  207.  header('Location:entry_history.php');
  208. }
  209.  echo "data has been inserted into database";
  210.  
  211. echo $que; exit;
  212. mysql_close($conn);
  213.  
  214. ?>
Apr 28 '16 #1
2 6248
Expand|Select|Wrap|Line Numbers
  1. your submit page
  2.  
  3.  
  4.  
  5. <?php
  6. session_start();
  7. $date = $_SESSION['date'];             
  8. $channel_name = $_SESSION["channel_name"];?>
  9.  
  10. <?php include("sql_conn.php");
  11. $num = $_POST['reza'];
  12.  
  13. for($i>0;$i<=$num;$i++)
  14. {
  15. if(isset($_REQUEST["title$i"])){$title = $_REQUEST["title$i"];}
  16. if(isset($_REQUEST["start_time$i"])){$start_time = $_REQUEST["start_time$i"];}
  17. if(isset($_REQUEST["end_time$i"])){$end_time = $_REQUEST["end_time$i"];}
  18. if(isset($_REQUEST["duration$i"])){$duration = $_REQUEST["duration$i"];}
  19. if(isset($_REQUEST["sponsor$i"])){$sponsor = $_REQUEST["sponsor$i"];}
  20. if(isset($_REQUEST["peak_offpeak$i"])){$peak_offpeak = $_REQUEST["peak_offpeak$i"];}
  21. if(isset($_REQUEST["program_name$i"])){$program_name = $_REQUEST["program_name$i"];}
  22. if(isset($_REQUEST["sub_brand_name$i"])){$sub_brand_name = $_REQUEST["sub_brand_name$i"];}
  23. if(isset($_REQUEST["product_name$i"])){$product_name = $_REQUEST["product_name$i"];}
  24.  
  25. $sql = "Insert Into entry_history (date,channel_name,title,start_time,end_time,duration,sponsor,peak_offpeak,program_name,sub_brand_name,product_name) Values('$date','$channel_name','$title','$start_time','$end_time','$duration','$sponsor','$peak_offpeak','$program_name','$sub_brand_name','$product_name')"; 
  26. $result=mysql_query($sql) or die(mysql_error());
  27.  
  28. echo ($sql);
  29. }
  30. header('location:entry_history.php');
  31.  
  32.  
  33. ?>
  34.  
  35.  
  36.  
  37.  
Jun 18 '16 #2
Step1 : Determining the correct SQL Insert command
When you have it write data to a database , if it's used sql statemant , specially the insert command.
i)Login into your cpanel and it's phpmyadmin icon.
ii)You choose then left menu bar , first to click database name and then click the table work.
iii)Top menu to insert data
iV)You've copy it sql statement to a temporay location , such as a text file on your own computer.
step 2 : Now to write php code that will excute mysql query.
Now We have modify data for smaple query we need it modify it run data for submitted comment.
step 3 : Now placing our php code on your pages.
Create a file named manage_comments.php
Paste in the sample code above
Update both page1.php and page2.php to include manage_comments.php by using
<? include("manage_comments.php"); ?>
at the top of the file


<? include("manage_comments.php"); ?>

<h1>This is page1.php</h1>

<div><a href='page2.php?id=2'>Click here</a> to go to page2.php</div>

<div style='margin:20px; width:100px; height:100px; background:blue;'></div>

<? include("formcode.php"); ?>
Jun 20 '16 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Chand | last post by:
Private Sub tbDate_AfterUpdate() Dim cnn As New ADODB.Connection Dim rst As New ADODB.Recordset rst.CursorLocation = adUseClient Set cnn = CurrentProject.Connection rst.Open "SELECT * FROM...
0
by: Rabothe | last post by:
I have created an excel report and i have visual basic macros running. Now i want to insert borders using VB macros. How do i do that? If the report returns 5 row then the border should be around...
8
by: cygsoft | last post by:
Hi, I have got the codings for inserting and displaying the records in the database. But i couldn't able to delete a specific row, which is created dynamically. i.e, if i give any one of the...
2
kaleeswaran
by: kaleeswaran | last post by:
hi! i want to know ..how to getting multiple rows from the database using ajax.and i pass these value to the javascript.give me solution... ...
0
by: akshalika | last post by:
I am new to Biztalk. In my project we need to connect oracle database and insert data into oracle table using BizTalk project. I use WCF Adapter pack(SP2). I create biztalk project then using Consume...
1
by: ronakinuk | last post by:
how to insert multiple rows in excel using vba how to insert multiple rows in excel using vba how to insert multiple rows in excel using vba
1
by: miyotz | last post by:
Hi. I have here my Javascript code that adds dynamic textbox (row) my problem is how can I save this to database using PHP script? How you can help me guys.. Thanks! <script...
1
by: pallabpal87 | last post by:
Hi! I am trying to insert a record in sql database using vb.net dataadapter, datatable, and datarow features. I use the following code. But it show me an error.(Object reference not set to an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.