Friday, 25 May 2018

insert multiple fields using foreach loop


create  a  table     students:

     create table  students
 (id   int primary key auto_increment,
   name    varchar(200),
  age  varchar(200)


if (isset($_POST['submit'])) {
$i = 0;
    foreach ($_POST as $val) {
         $name = $_POST['name'][$i];
    $age = $_POST['age'][$i];


$sql="INSERT INTO students (name,age) VALUES ('$name','$age')";



echo "record inserted";


<h1>Add user</h1>
 <form method="post" action="test.php">


        <td><input name="name[]" type="text" /></td>
        <td><input name="age[]" type="text" /></td>

        <td><input name="name[]" type="text" /></td>
        <td><input name="age[]" type="text" /></td>

        <td><input name="name[]" type="text" /></td>
        <td><input name="age[]" type="text" /></td>

 <input type="submit" name="submit" value="Submit" />

Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.


  1. thanks for sharing the information.
    Indian Cyber Army’s most awaited internship is live now. Summer Internship 2018 on “ Ethical hacking” and book your seats before it runs out.Candidates have to get themselves registered to be a part of this Internship program. Here internship will give you on-the-job experience, help you learn whether you and Cyber security industry are a good match and can provide you with valuable connections and references. Here interns are usually exposed to a wide variety of tasks and responsibilities which allows the intern to showcase their strengths by working on projects for various managers that work on different parts of Indian Cyber Army. Becoming a high performing intern is a fantastic way to improve your employment prospects. This internship can be a great way to get your foot in the door of success with a prestigious or desirable Organization.As career in ethical hacking is most in demand.

  2. Thanks for such important information.keep up the good work.Ethical Hacking training is based on current industry standards that helps attendees to secure placements in their dream jobs at MNCs. Indian Cyber Army Provides Best Ethical Hacking Training in India.Indian Cyber Army credibility in Ethical hacking training & Cybercrime investigation training is acknowledged across nation as we offer hands on practical knowledge and full assistance with basic as well as advanced level ethical hacking & cybercrime investigation courses

  3. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your blog.
    ios app development course
    iPhone training institute in bangalore

  4. Shahni Digital Media provides complete digital marketing solutions to your business. e.g. ppc, social media marketing, web designing & development. Hire us to grow up your business high.

    Digital Marketing Company Bhopal
    Website Designing Company Bhopal
    SEO Company in Bhopal
    ORM Company India


PHP Training Mumbai, PHP MySQL Training Mumbai, PHP Course Mumbai, PHP Institute Mumbai


© 2013 PHP TRAINING IN MUMBAI BY OM SIR . All rights resevered. Designed by OM SIR

Back To Top