We help IT Professionals succeed at work.
Get Started

Insert multiple html form fields into mysql table using PHP

bcmeyer1983 asked
Last Modified: 2013-12-13
Here is my HTML Code:

<title>Record Insertion>
<form action="insert.php" method="POST">
<p>The First Hale Database<br>
Age <input type="text" name="Age" size="2"><br>
First Name <input type="text" name="First_Name" size="30"><br>
Last Name <input type="text" name="Last_Name" size="30"> <br>
<p><input type="submit" name="submit" value="Add Me"></p>

Here is my PHP code:

$mysqli = new mysqli("localhost", "root", "pass", "test");

if (mysqli_connect_errno()) {
      printf("Connect failed: %s\n", mysqli_connect_error());
} else {
      $sql = "INSERT INTO testTable (Age)
            VALUES ('".$_POST["Age"]."')";
            $res = mysqli_query($mysqli, $sql);

-----------------missing the rest of the form INSERT INTO here only inserting Age------------------------
      if ($res === TRUE) {
            echo "record has been inserted";
      } else {
            printf("could not insert record: %s\n", mysqli_error($mysqli));

Using text books. I am training myself with mysql and php. I have inserted my first value into my first database/database table using the above form and script. However this is just basic and as you can see I have additional form fields in my html that i would like to insert into my test database/testtable. the database is ready to accept these posts, however what is an "experienced" way the PHP code should read for the rest of my HTML form fields?
Watch Question
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE