473,395 Members | 1,972 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,395 software developers and data experts.

Process Multi Record Form

Hi,

Iam pulling my hair for the below problem since many days!

1. Display a multi record block in a form through PHP

2. On click of submit button, form should collect the data from multi record block and store them in DB using mySQL

If this forum can help on this problem, I am eternally greatful.

Thanks
A PHP Lover
Jan 13 '12 #1
1 1445
dlite922
1,584 Expert 1GB
Usually you need to be more specific, give us code and tell us where you're stuck, but here's a quick run down in pseudo-code:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // get the $records you want to display if any
  4.  
  5. if($_POST['save']) {
  6.    $db = <create_db_connection>;
  7.    $firstArr = $_POST['first']; 
  8.    $secondArr = $_POST['second'];
  9.  
  10.    // do your validation, if using mysql, use mysql_real_escape_string() function 
  11.    // if validation successfull, loop and save to DB
  12.  
  13.    for($i = 0; isset($firstArr[$i]); $i++) {
  14.        // save value to db
  15.        $db->query("INSERT INTO table SET first = '{$firstArr[$i]}', second = '{$secondArr[$i]}';");
  16.  
  17.    }
  18.  
  19.    // go to next page using header("Location: newpage?status=success");
  20.    // or just display a message
  21.  
  22.  
  23. }
  24. ?>
  25. .
  26. . HTML HEADERS
  27. <form method='post' action='' >
  28. <table>
  29. <?php 
  30.    // create record block (assuming $records is an array of objects)
  31.    foreach($records as $rec) {
  32.      echo "<tr><td>";
  33.      echo "<input type='text' name='first[]' value='$rec->first' />";
  34.      echo "</td><td>";
  35.      echo "<input type='text' name='second[]' value='$rec->second' />";
  36.      echo "</td></tr>"; 
  37.    }
  38. ?>
  39. </table>
  40. <input type="submit" name="save" value="Save Records" />
  41. </form>
  42. .
  43. .
  44. .
  45. END HTML footer
  46.  
Let me know if any questions,


Dan
Jan 13 '12 #2

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

Similar topics

3
by: sentinel | last post by:
Hi, Wonder if anyone can help with this problem: I am using an app with several pages, using a session to track vars between the pages, and using an image map to re-direct back and forwards...
1
by: mmac | last post by:
I have been investigating how to create a multi page form in Frontpage that eventually will allow an emailed result. I can write the asp to "post" from one page to the next easily enough but when...
2
by: Jishnu | last post by:
HI All, I am writing a multi page form. I am using hidden input statements to pass my variables between different pages. Now I want to provide a page whereusers can update the previous entered...
5
by: Rose | last post by:
I want to use the javascript dom to reference the field of a record in a multi-record html form when that field has been changed. How do I reference the field? I have a JavaScript function coded...
3
by: omozali | last post by:
Hi, How I can create a multi tap form. I used to remember how few years ago but not any more I mean many forms shown on the screen and accessed by clicking on their tap just like in excel
1
by: alex.gruenther | last post by:
I am new to Access and need help creating an edit record form. I've got a table called Player with attributes like name, address, phone, etc. I've created an edit player form with a combo box...
2
by: beenanic | last post by:
How I can read a parameter from a multi-part form?
7
by: gmiotke | last post by:
I know that this is easy for those that know but alas this is not me ;) I have a multi part form that is going to write to a dB. As a point of reference I can offer geico.com (i.e., the quote...
3
by: needanswer | last post by:
Can I save values from the multi same form? How? Sample: on this form - one datagridview, one textbox, one combobox. Thanks.
4
by: needanswer | last post by:
Is possible to have different values of combobox on the multi same form? Actually I want to make a multi same form, but with one combobox to set the authority. When different persons to use this...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.