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.


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