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>
- In our first step, we write <HTML>, which tells the browser what HTML version we're using. Documents in HTML begin with tags.
- Using the <head> tag, we will explain the project's heading.
- <title> are open and </title> and then head closed using </head>
- To define the body of the webpage, the <body> tag is used. This is where we write all the content on our website.
- Then we use <p> tag for paragraph.
- Then we use the <label> tag defines a label for several elements: <input type="checkbox">
- then we use <form id="form" tag for creating a form in the program.
- 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.
- 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.