All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

How To Insert Data Into MySQL Db Using Form In PHP Database

Last Updated : Mar 11, 2024

How To Insert Data Into MySQL Db Using Form In PHP Database

In this article we will show you the solution of how to insert data into MySQL DB using form in PHP database, it is then possible to begin adding data to the database and table that have been created.

It inserts data into the MySQL database, which is the most important line of PHP code.

A database table is updated by inserting data with an INSERT INTO statement. The table Students is being updated in this example.

Server-side scripting languages such as PHP enable the storage of data in databases during the processing of requests. Using PHP, I will illustrate inserting data using a SQL insert query.

The following rules should be followed when writing syntax -

  • PHP requires quotation marks around SQL queries
  • There must be quotation marks around string values inside a SQL query
  • There must be no quotation marks around numeric values

Step By Step Guide On How To Insert Data Into MySQL DB Using Form In PHP Database :-

<!DOCTYPE html>
<html lang="en">
   <head>
      <title>GFG- Store Data</title>
   </head>
   <body>
      <center>
         <h1>Storing Form data in Database</h1>
         <form action="insert.php" method="post">
<p>
               <label for="firstName">First Name:</label>
               <input type="text" name="first_name" id="firstName">
            </p>
<p>
               <label for="lastName">Last Name:</label>
               <input type="text" name="last_name" id="lastName">
            </p>
<p>
               <label for="Gender">Gender:</label>
               <input type="text" name="gender" id="Gender">
            </p>
<p>
               <label for="Address">Address:</label>
               <input type="text" name="address" id="Address">
            </p>
<p>
               <label for="email Address">Email Address:</label>
               <input type="text" name="email" id="email Address">
            </p>
            <input type="submit" value="Submit">
         </form>
      </center>
   </body>
</html>
  1. In our first step, we write <HTML>, which tells the browser what HTML version we're using. Documents in HTML begin with tags.
  2. Using the <head> tag, we will explain the project's heading.
  3. <title> are open and </title> and then head closed using </head>
  4. To define the body of the webpage, the <body> tag is used. This is where we write all the content on our website.
  5. Then we use <p> tag for paragraph.
  6. Then we use the <label> tag defines a label for several elements: <input type="checkbox">
  7. then we use <form id="form" tag for creating a form in the program.
  8. This form. Submitting a form can be done using the submit () method. There is a similar process when activating the submission button on a form, but it is different from activating it.
  9. After that </form></center></body></html> and code should be executed after closed all tags.

Conclusion :-

We also have the names of the columns in the table between the parenthesis: (name, last name, email). A data set will be added in accordance with the specified order.

The values would be added in the wrong order if we wrote (email, last name, name).

I hope this article on how to insert data into MySQL DB using form in PHP database helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Pragati

Experienced coding content writer who enjoys breaking down complex concepts in programming languages like Java, Python, C, and C++. Over three years of experience producing interesting and relevant content for a variety of entities. Committed to providing concise and easy-to-understand articles that assist readers in easily understanding technology and industry trends in the world of coding and software development.

Follow Pragati On Linkedin 🡪