Chuyển tới nội dung
Home » Html Form Php Mysql | Php – A Simple Html Form

Html Form Php Mysql | Php – A Simple Html Form

How to Connect HTML Form with MySQL Database using PHP

Connecting to the Database

A database is a collection of data. It is a way to store and retrieve data from a computer or server.

Xampp stands for “Extended Apache MySQL Platform”. It is a free and open-source software that allows you to run a database server on your computer. It utilizes MySQL, Apache, PHP and Perl as its database engine, and it is free to use.

When to use POST?

Information sent from a form with the POST method is invisible to others (all names/values are embedded within the body of the HTTP request) and has no limits on the amount of information to send.

Moreover POST supports advanced functionality such as support for multi-part binary input while uploading files to server.

However, because the variables are not displayed in the URL, it is not possible to bookmark the page.

Developers prefer POST for sending form data.

Next, lets see how we can process PHP forms the secure way!

Collecting customer form data is a common task in web development. Contact forms make your site more professional and send a clear signal that you’re interested in doing business with your potential clients. The lack of one could make your business seem outdated or unprofessional. People are more likely to patronize your products if you’re highly accessible. This is a great way to increase your business’s visibility.

Other reasons to implement a contact form:

  1. It makes your site more professional
  2. Security
  3. Makes yourself more reachable
  4. Automate email responses

Today, we will be learning how to insert customer form data into a MySQL database using HTML and PHP. We will be creating an HTML form and a PHP script to insert the data into the database using

phpMyAdmin

.

How to Connect HTML Form with MySQL Database using PHP
How to Connect HTML Form with MySQL Database using PHP

Step 4: Create a PHP page to save data from HTML form to your MySQL database

The contact HTML form action is on “contact.php” page. On this page, we will write code for inserting records into the database.

For storing data in MySQL as records, you have to first connect with the DB. Connecting the code is very simple. The mysql_connect in PHP is deprecated for the latest version therefore I used it here

mysqli_connect.


$con = mysqli_connect("localhost","your_localhost_database_user","your_localhost_database_password","your_localhost_database_db");

You need to place value for your localhost username and password. Normally localhost MySQL database username is root and password blank or root. For example, the code is as below


$con = mysqli_connect('localhost', 'root', '',’db_contact’); The “db_contact” is our database name that we created before. After connection database you need to take post variable from the form. See the below code $txtName = $_POST['txtName']; $txtEmail = $_POST['txtEmail']; $txtPhone = $_POST['txtPhone']; $txtMessage = $_POST['txtMessage'];

When you will get the post variable then you need to write the following SQL command.


$sql = "INSERT INTO `tbl_contact` (`Id`, `fldName`, `fldEmail`, `fldPhone`, `fldMessage`) VALUES ('0', '$txtName', '$txtEmail', '$txtPhone', '$txtMessage');"

For fire query over the database, you need to write the following line


$rs = mysqli_query($con, $sql);

Here is PHP code for inserting data into your database from a form.

PHP – Complete Form Example

Here is the complete code for the PHP Form Validation Example:

Get Started With Machine Learning

Learn the fundamentals of Machine Learning with this free course. Future-proof your career by adding ML skills to your toolkit — or prepare to land a job in AI or Data Science.

This Answer outlines how to use PHP to connect an HTML form to a MySQL database. We’ll use XAMPP as the server software to create a database and run PHP.

We’ll use the below steps to create a connection:

The method to configure a PHP development environment with XAMPP is shown here.

This Answer explains what an HTML form is and how to create it.

In this step, we’ll create a simple MySQL database since our server is already running.

We’ll open the browser and type http://localhost/phpmyadmin/. This redirects us to the PHP admin page, where we can create and manage databases. Click on the New option in the menu panel on the left side. The image below demonstrates this:

On the next page, we’ll choose a name for our database and click on Create, as shown:

Next, we’ll create a table in the database. We’ll add a table name and choose the number of columns:

Once we click on Create, we’ll be redirected to the following page:

Here, we’ve to give details regarding the table. The columns correspond to our fields in the HTML form. We may also assign each column a data type, characters length, or special privileges such as the

Once we’re done, we’ll click on Save. Our first table in the database is created.

Now that we have our database and server ready, we’ll create the necessary files. We’ll begin by opening the folder directory containing XAMPP. We traditionally find this folder in Local Disk E or Local Disk C. For Linux users, this will be in the

Computer/opt/lampp

directory.

Within that folder, open another folder titled

htdocs

and create a folder in it. We can name it anything, but for this tutorial, we’ll name it

educativeform

. This new folder will contain our HTML and PHP files.

htdocs/educativeform|-> form.php|-> index.html

The following code snippet contains the HTML code for the form:

Note: If we click on the submit button, it will given an error since we haven’t yet connected it to the database.


POSTis the connection type to send the HTML form entries. The


actionattribute has the value


form.php. This is the name of the PHP file in the working directory, and the form entries will be sent to this file upon submission.


formfields. The last


inputtype is a


buttonthat submits the field values to the PHP file.

To confirm that our form is ready, we’ll type

localhost/educativeform

in the browser. This ensures that the server, MySQL, and Apache is running. Otherwise, we might get an error.

Next, we’ll create the PHP file. The sample code, along with the explanation, is given below:


$_POSTas connection type to get HTML form entries.


nameattribute in the


inputlabels of the HTML code.

Finally, we’ll connect our HTML form to the database using PHP. The code below is an addition to the previous code snippet, as shown:


mysqli_connectto create a connection.

If everything is running without errors, we should be able to add our HTML form details in the MySQL database.

RELATED TAGS

CONTRIBUTOR

Careers

Insert HTML Form to MySQL Database With PHP In Easy Way | PHP for Beginners
Insert HTML Form to MySQL Database With PHP In Easy Way | PHP for Beginners

GETPOST

Both GET and POST create an array (e.g. array( key1 => value1, key2 => value2, key3 => value3, …)). This array holds key/value pairs, where keys are the names of the form controls and values are the input data from the user.

Both GET and POST are treated as $_GET and $_POST. These are superglobals, which means that they are always accessible, regardless of scope – and you can access them from any function, class or file without having to do anything special.

$_GET is an array of variables passed to the current script via the URL parameters.

$_POST is an array of variables passed to the current script via the HTTP POST method.

Processing form data:

We can collect the form data submitted through our HTML form that we’re going to create. We can use the

$_REQUEST

variable to collect the data.



close(); ?>

Connect Your HTML Form to MySQL with PHP: Step-by-Step Tutorial
Connect Your HTML Form to MySQL with PHP: Step-by-Step Tutorial

Process:

First, you’ll want to make sure that you already have XAMPP Server installed on your local machine. Once it’s installed, let’s begin by first opening up our Xampp application. In my case, I am using a Macbook Pro so things may look a little different if you’re using Windows or another operating system. You’ll want to make sure you have the following services running when you open up your Xampp application:

  1. MySQL Database
  2. Apache Web Server

Now we can navigate over to

localhost/phpmyadmin

and create a database and table.

  • Click on

    New

    and then type in the name of your Database. We are going to name our database

    SampleDB

    . Once complete, go ahead and click the

    Create

    button.

Next we can create the table we want to use named

SampleTable

. Make sure to set the number of columns to 5. Once complete, click the

Create

button.

Now that our Database and Sample table is created, we can enter our columns and click on save.

Make sure you enter the correct data type for each column.


  • first_name

  • last_name

  • gender

  • address

Also, make sure to add the appropriate type of

VARCHAR

to each item as well.

Step 3: Create HTML form for connecting to database

Now you have to create an HTML form. For this, you need to create a working folder first and then create a web page with the name “contact.html”. If you install xampp your working folder is in folder this “E:\xampp\htdocs”. You can create a new folder “contact” on your localhost working folder. Create a “contact.html” file and paste the following code.


<br /> Contact Form - PHP/MySQL Demo Code<br />

Contact Form



Now your form is ready. You may test it in your localhost link http://localhost/contact/contact.htmlIn the next step, I will go with creating PHP / MySQL code.

Save HTML Form Data to a MySQL Database using PHP
Save HTML Form Data to a MySQL Database using PHP

Create the html form

Now it’s time to create our HTML form. We will be using this form to send the data to our database.

Filename:

index.php


<br /> Sample Form<br />


Storing Form data in Database




HTDOCS Folder

We can access this folder by opening up our Xampp application and then clicking on

Open Application Folder

.

This will open up our Xampp files directory. Navigate to the

htdocs

folder and copy your

index.php

and

insert.php

files directly into this directory. This will overwrite the existing file. Now we can head over to

localhost/index.php

to fill out the form submit it to our database.

Fill out the form and then click

submit

. Great! it looks like our data has been successfully stored in our DB.

Head over to

localhost/phpmyadmin

and select your database to ensure that our data was successfully inserted.

How to Connect HTML Form with MySQL Database using PHP
How to Connect HTML Form with MySQL Database using PHP

PHP – A Simple HTML Form

The example below displays a simple HTML form with two input fields and a submit button:

Example

Name:

E-mail:

When the user fills out the form above and clicks the submit button, the form data is sent for processing to a PHP file named “welcome.php”. The form data is sent with the HTTP POST method.

To display the submitted data you could simply echo all the variables. The “welcome.php” looks like this:

Welcome

Your email address is:

The output could be something like this:

Your email address is [email protected]

The same result could also be achieved using the HTTP GET method:

Example

Name:

E-mail:

and “welcome_get.php” looks like this:

Welcome

Your email address is:

The code above is quite simple. However, the most important thing is missing. You need to validate form data to protect your script from malicious code.

Think SECURITY when processing PHP forms!

This page does not contain any form validation, it just shows how you can send and retrieve form data.

However, the next pages will show how to process PHP forms with security in mind! Proper validation of form data is important to protect your form from hackers and spammers!

Conclusion

You have just completed the basic steps to store data in a database using HTML and PHP. You can now use this method to create any kind of form you like and attach it to a phpMyAdmin database.

🤝 Thank you so much for taking time out of your day to read this Article! I hope it helped you out and you learned something new today! Please leave a comment if you have anything you’d like to add. I’d love to hear from you!

Advance Shopping Cart With Admin Panel And Checkout System Using PHP and MySQL | P3 - Add To Cart
Advance Shopping Cart With Admin Panel And Checkout System Using PHP and MySQL | P3 – Add To Cart

Step 2: Create a database and a table in MySQL

Open a web browser (chrome, firefox, edge, etc., ) and type this http://localhost/phpmyadmin/ or http://127.0.0.1/phpmyadmin/ for open GUI for managing DB on your computer. See the xampp screen below how it is coming.

Click on the databases link and create your db by the name “db_contact”. See the image below:

After creating your DB you need to create a table by any name I choose “tbl_contact” with the number of field 5. We choose 4 fields on top Name, Email, Phone, and Message. The first column we will keep for maintaining the serial number and in technical terms primary key(unique number of each recor). See the image below

When you will click to go button you will get this screen. Now we need to feed every field information.

See the below image in which I added field information. So for field Name used field Name – fldName, Email – fldEmail, Phone – fldPhone, Message – fldMessage.

Now click on the save button that is on the bottom right of your screen. After saving your table it is created in your database.

You can create your DB and table using the SQL below. You have to copy the following code and paste it into your MySQL GUI phpmyadmin database or any other GUI or command prompt. At the bottom of the blog, you will get a git download link to download the SQL file.


-- -- Database: `mydb` -- CREATE DATABASE IF NOT EXISTS `db_contact` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci; USE `db_contact`; -- -------------------------------------------------------- -- -- Table structure for table `tbl_contact` -- DROP TABLE IF EXISTS `tbl_contact`; CREATE TABLE IF NOT EXISTS `tbl_contact` ( `id` int(11) NOT NULL, `fldName` varchar(50) NOT NULL, `fldEmail` varchar(150) NOT NULL, `fldPhone` varchar(15) NOT NULL, `fldMessage` text NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Indexes for dumped tables -- -- -- Indexes for table `tbl_contact` -- ALTER TABLE `tbl_contact` ADD PRIMARY KEY (`id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `tbl_contact` -- ALTER TABLE `tbl_contact` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

PHP


<br /> Insert Page page<br />


$conn


= mysqli_connect(


"localhost"


"root"


""


"staff"


);


if


$conn


=== false){


die


"ERROR: Could not connect. "


. mysqli_connect_error());


$first_name


$_REQUEST


'first_name'


];


$last_name


$_REQUEST


'last_name'


];


$gender


$_REQUEST


'gender'


];


$address


$_REQUEST


'address'


];


$email


$_REQUEST


'email'


];


$sql


= "INSERT INTO college VALUES (


'$first_name'


'$last_name'


'$gender'


'$address'


'$email'


)";


if


(mysqli_query(


$conn


$sql


)){


echo


"

data stored in a database successfully."


" Please browse your localhost php my admin"


" to view the updated data"


echo


nl2br


"\n$first_name\n $last_name\n "


"$gender\n $address\n $email"


);


else


echo


"ERROR: Hush! Sorry $sql. "


. mysqli_error(


$conn


);


mysqli_close(


$conn


);


?>

Output: Type localhost/7058/index.php in your browser, it will display the form. After submitting the form, the form data is submitted into database.

Let’s check in our database

PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples.

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about!

Last Updated :
19 May, 2022

Like Article

Save Article

Share your thoughts in the comments

Please Login to comment…

PHP Complete Form Example

This chapter shows how to keep the values in the input fields when the user hits the submit button.

How To Make Login & Register Form With User & Admin Page Using HTML - CSS - PHP - MySQL Database
How To Make Login & Register Form With User & Admin Page Using HTML – CSS – PHP – MySQL Database

Step 5: All done!

Now the coding part is done. Download code from github

If you would like to check then you can fill the form http://localhost/contact/contact.html and see the result in the database. You may check via phpmyadmin your inserted record.

Why skills as a custom PHP developer?

Php is the most popular server-side programming language. It is used more than 70% in comparison to other website development languages. As a lot of CMS and custom PHP applications developed already on PHP, therefore, it will be a demanding language for the next 5 years.

The worldwide PHP development company is looking for cheap PHP developers in India. Many companies also like to freelance PHP developers in Delhi, London, Bangalore, Mumbai (locally). If you would like to hire a dedicated developer then you need to skills yourself.

See more answer about PHP script connect to Mysql on Facebook Group

Please join Facebook group for discussion click herePost your question here with the HASH tag #connectphpmysql #connecthtmlmysql . We will approve and answer your question.

Please view more answer on this hashtag on Facebook Group #connectphpmysql #connecthtmlmysql

In this article, we are going to store data in database which is submitted through HTML form.

Requirements:

HTML form: First we create an HTML form that need to take user input from keyboard. HTML form is a document which stores information of a user on a web server using interactive controls. An HTML form contains different kind of information such as username, password, contact number, email id etc.

The elements that are used in an HTML form are check box, input box, radio buttons, submit buttons etc. With the help of these elements, the information of an user is submitted on the web server. The form tag is used to create an HTML form.

Syntax:

Form Elements…

or

To pass the values to next page, we use the page name with the following syntax. We can use either GET or POST method to sent data to server.

Form Elements…

Database Connection: The collection of related data is called a database. XAMPP stands for cross-platform, Apache, MySQL, PHP, and Perl. It is among the simple light-weight local servers for website development. In PHP, we can connect to database using localhost XAMPP web server.

Syntax:

PHP – Keep The Values in The Form

To show the values in the input fields after the user hits the submit button, we add a little PHP script inside the value attribute of the following input fields: name, email, and website. In the comment textarea field, we put the script between the

tags. The little script outputs the value of the $name, $email, $website, and $comment variables.

Then, we also need to show which radio button that was checked. For this, we must manipulate the checked attribute (not the value attribute for radio buttons):

E-mail:

Website:

Comment:

Gender:

value=”female”>Female

value=”male”>Male

value=”other”>Other

Shopping Cart With Multiple User Login & Register System Using HTML - CSS - PHP - MySQL Database
Shopping Cart With Multiple User Login & Register System Using HTML – CSS – PHP – MySQL Database

How to connect HTML to database with MySQL using PHP? An example – This article helps to become a custom PHP developer. You will get complete steps for storing HTML form input field in MySQL database connection in a db table using the PHP programming with example . This article provide you HTML form, DB + Table SQL code, Bootstrap 5 with CSS, Form Validation and database connection + submission code . In the conclusion step, you will be GIT download link so no need to copy-paste the code.

PHP


if


$_SERVER


"REQUEST_METHOD"


] ==


"POST"


) {


$data


$_REQUEST


'val1'


];


if


empty


$data


)) {


echo


"data is empty"


else


echo


$data


?>


$conn


->close();


?>

Complete Steps to Design Project:

  • Start XAMPP Server.
  • Open localhost/phpmyadmin in your web browser.
  • Create database of name staff and table of name college.
  • Write HTML and PHP code in your Notepad in a particular folder.
  • Submit data through HTML Form.
  • Verify the results.

Steps In detail:

  • Start XAMPP Server by opening XAMPP and click on XAMPP Start.
  • Open localhost/phpmyadmin in your web browser and create database with database name as staff and click on create.
  • Then create table name college.
  • Enter columns and click on save
  • Now open Notepad and start writing PHP code and save it as index.php and open other notepad and save it as insert.php Save both files in one folder under htdocs.

Filename: index.php

Setting up your Xampp Server

In order to successfully connect to the database and send over our form data, we need to set up our Xampp server to accept the incoming data:

  • First we need to start our Xampp server.
  • Navigate to

    localhost/phpmyadmin

    .
  • Create a database name of

    SampleDB

    and a table name of

    SampleTable

    .
  • Create our HTML and PHP files in our Code Editor. I am using Visual Studio Code.
  • Submit our data through the form we created.
  • Check the results and verify that all data was successfully inserted.
16 | Create a Database in MySQL PHP Tutorial | 2023 | Learn PHP Full Course for Beginners
16 | Create a Database in MySQL PHP Tutorial | 2023 | Learn PHP Full Course for Beginners

Instructions:

As an example, the first thing we will need to do is create our

HTML

form. An HTML Form is a document that stores information about the user’s interaction with a website. The form is a way for the user to send information to the database.

Form Elements...

The

action

attribute tells the form where to send the data. The

method

attribute tells the form how to send the data.

When to use GET?

Information sent from a form with the GET method is visible to everyone (all variable names and values are displayed in the URL). GET also has limits on the amount of information to send. The limitation is about 2000 characters. However, because the variables are displayed in the URL, it is possible to bookmark the page. This can be useful in some cases.

GET may be used for sending non-sensitive data.

Note: GET should NEVER be used for sending passwords or other sensitive information!

How To Make Login & Register System With User Profile / Avatar Image Using HTML - CSS - PHP - MySQL
How To Make Login & Register System With User Profile / Avatar Image Using HTML – CSS – PHP – MySQL

PHP


$servername


"localhost"


$username


"username"


$password


"password"


$dbname


"database_name"


$conn


new


mysqli(


$servername


$username


$password


$dbname


);


if


$conn


->connect_error) {


die


"Connection failed: "


$conn


->connect_error);


$sqlquery


= "INSERT INTO table VALUES


'John'


'Doe'


'[email protected]'


)"


if


$conn


->query(


$sql


) === TRUE) {


echo


"record inserted successfully"


else


echo


"Error: "


$sql


""


$conn


->error;

How to get form data: We are going to collect the form data submitted through HTML form. PHP $_REQUEST method is a PHP super global variable which is used to collect data after submitting the HTML form.

Syntax:

Tools Required to connect HTML Form with MySQL Database using PHP

Article Contents

  • Tools Required to connect HTML Form with MySQL Database using PHP
  • Step 1: Filter your HTML form requirements for your contact us web page
  • Step 2: Create a database and a table in MySQL
  • Step 3: Create HTML form for connecting to database
  • Step 4: Create a PHP page to save data from HTML form to your MySQL database
  • Step 5: All done!
  • Why skills as a custom PHP developer?
  • See more answer about PHP script connect to Mysql on Facebook Group
  • Related Posts:

First of all, you must be install any XAMPP or WAMP or MAMP (for Mac OS) kind of software on your laptop or computer. With this software, you will get a local webserver i.e. Apache, PHP language, and MySQL database. The complete code is on Github and the download link is the last of this article.

In this article, my PHP, MySQL example is with database connection in xampp code.

After installation you need to on the Xampp see the image below:

After installation of any of these laptop or desktop software you need to check your localhost is working or not. Open your browser and check this URL http://127.0.0.1 or http://localhost/ . If this is working it means you have the local webserver activated with PHP/MySQL.

Also, GUI PHPmyAdmin coming for handling CRUD operations i.e. insert(create), update, delete, and select(read) records from tables. This interface is browser-based and very helpful, easy to use for creating and managing phpmyadmin database in table(column, row).

If you have the above installation you can go ahead to start your coding.

If you have not a LAMP stack-based web server then you can do this directly in your hosting space.

If you have any more query then you can comment on this post. We will reply to your query.

Watch Video

Suppose you have a web page to insert contact form field data in your DB. For this you need to follow the following steps:

Responsive Login and Register Forms | Admin authentication PHP MySQL 2024
Responsive Login and Register Forms | Admin authentication PHP MySQL 2024

Create the php script

Now we need to create our PHP script. This is the script that will process our form data and insert it into our database.

Filename:

insert.php


<br /> Insert Page page<br />




localhost // username => root // password => empty // database name => staff $conn = mysqli_connect("localhost", "root", "", "sampleDB"); // Check connection if($conn === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } // Taking all 5 values from the form data(input) $first_name = $_REQUEST['first_name']; $last_name = $_REQUEST['last_name']; $gender = $_REQUEST['gender']; $address = $_REQUEST['address']; $email = $_REQUEST['email']; // We are going to insert the data into our sampleDB table $sql = "INSERT INTO sampleDB VALUES ('$first_name', '$last_name','$gender','$address','$email')"; // Check if the query is successful if(mysqli_query($conn, $sql)){ echo ""; echo nl2br("\n$first_name\n $last_name\n " . "$gender\n $address\n $email"); } else{ echo "ERROR: Hush! Sorry $sql. " . mysqli_error($conn); } // Close connection mysqli_close($conn); ?>



Great! Now we can submit our form data to our database but first we need to save our

index.php

and

insert.php

files inside of our

htdocs

folder located inside our Xampp directory.

Example PHP Code:



connect_error) { die("Connection failed: " . $conn->connect_error); } // Insert into appropriate table $sqlquery = "INSERT INTO table VALUES ('John', 'Doe', '[email protected]')" // If the connection is successful, run the query if ($conn->query($sql) === TRUE) { echo "record inserted successfully"; // If the query is not successful, display the error message } else { echo "Error: " . $sql . "" . $conn->error; } ?>

how to store html form data in mysql database using java | Java Servlet and JDBC Example
how to store html form data in mysql database using java | Java Servlet and JDBC Example

PHP insert dữ liệu vào MySQL thông qua form

  • Bài trước đã hướng dẫn cách thêm dữ liệu bằng câu lệnh MySQL, bài này sẽ hướng dẫn cách kết hợp với form để insert dữ liệu.
  • Dữ liệu có thể là

    _GET

    hay

    _POST

    , tùy vào độ bảo mật của dữ liệu, xem lại _GET và P_OST
  • Các bước thực hiện:

    • Tạo form insert dữ liệu.
    • Kết nối database và table.
    • Lấy dữ liệu post từ form
    • Xử lý dữ liệu.
    • Đóng database.
  • Nếu chưa biết cách lấy dữ liệu từ form thì bạn xem lại phần xử lý form
Form dữ liệu
Tiêu đề:
Ngày tháng:
Mô tả:
Nội dung:


Xử lý dữ liệu insert

Kiểu hướng đối tượng


connect_error) { die(“Không kết nối :” . $conn->connect_error); exit(); } //Khai báo giá trị ban đầu, nếu không có thì khi chưa submit câu lệnh insert sẽ báo lỗi $title = “”; $date = “”; $description = “”; $content = “”; //Lấy giá trị POST từ form vừa submit if ($_SERVER[“REQUEST_METHOD”] == “POST”) { if(isset($_POST[“title”])) { $title = $_POST[‘title’]; } if(isset($_POST[“date”])) { $date = $_POST[‘date’]; } if(isset($_POST[“description”])) { $description = $_POST[‘description’]; } if(isset($_POST[“content”])) { $content = $_POST[‘content’]; } //Code xử lý, insert dữ liệu vào table $sql = “INSERT INTO tin_xahoi (title, date, description, content) VALUES (‘$title’, ‘$date’, ‘$description’, ‘$content’)”; if ($connect->query($sql) === TRUE) { echo “Thêm dữ liệu thành công”; } else { echo “Error: ” . $sql . “” . $connect->error; } } //Đóng database $connect->close(); ?>

Tiêu đề:
Ngày tháng:
Mô tả:
Nội dung:


Thêm dữ liệu thành công

  • Nếu không xảy ra lỗi gì, dữ liệu được insert thì sẽ xuất câu thông báo như trên.
Kiểu thủ tục

” . mysqli_error($connect); } } //Đóng database mysqli_close($connect); ?>

Tiêu đề:
Ngày tháng:
Mô tả:
Nội dung:


Thêm dữ liệu thành công

Trong file download đã có sẵn file tintuc.sql, file này là file dữ liệu mẫu, sau khi đã tạo database chúng ta có thể đưa dữ liệu từ file tintuc.sql bằng thao tác import có trong phpMyAdmin.

PHP Form Handling

The PHP superglobals $_GET and $_POST are used to collect form-data.

PHP




"en"



<br /> GFG- Store Data<br />

Storing Form data in Database


"insert.php"


method=


"post"





"text"


name=


"first_name"


id=


"firstName"





"text"


name=


"last_name"


id=


"lastName"





"text"


name=


"gender"


id=


"Gender"





"text"


name=


"address"


id=


"Address"





"text"


name=


"email"


id=


"emailAddress"



"submit"


value=


"Submit"

Filename: insert.php

Fill HTML Table From MySQL Database Using PHP | Display MySQL Data in HTML Table
Fill HTML Table From MySQL Database Using PHP | Display MySQL Data in HTML Table

Keywords searched by users: html form php mysql

How To Connect Html Form With Mysql Database Using Php - Youtube
How To Connect Html Form With Mysql Database Using Php – Youtube
How To Insert Form Data Into Database Using Php ? - Geeksforgeeks
How To Insert Form Data Into Database Using Php ? – Geeksforgeeks
Create A Simple Contact Form In Php With Mysql - Codespeedy
Create A Simple Contact Form In Php With Mysql – Codespeedy
Create Simple Working Contact Form Using Php Mysql Html And Bootstrap 4 -  Youtube
Create Simple Working Contact Form Using Php Mysql Html And Bootstrap 4 – Youtube
Php And Mysql How To Connect #Html #Login Form To #Php And #Mysql Part 2 -  Youtube
Php And Mysql How To Connect #Html #Login Form To #Php And #Mysql Part 2 – Youtube
User Registration Form With Php And Mysql Tutorial 1 - Creating A  Registration Form - Youtube
User Registration Form With Php And Mysql Tutorial 1 – Creating A Registration Form – Youtube
Php Mysql Login System - Javatpoint
Php Mysql Login System – Javatpoint
Signup Form Using Php And Mysql Database - Geeksforgeeks
Signup Form Using Php And Mysql Database – Geeksforgeeks
How To Connect Html Form With Mysql Database Using Php - Youtube
How To Connect Html Form With Mysql Database Using Php – Youtube
Login Form In Php: How To Create Login Form Using Php? | Simplilearn
Login Form In Php: How To Create Login Form Using Php? | Simplilearn
Php Registration Form
Php Registration Form
Php Mysql Login System - Javatpoint
Php Mysql Login System – Javatpoint
Secure Registration System With Php And Mysql
Secure Registration System With Php And Mysql
How To Insert Form Data Into Database Using Php ? - Geeksforgeeks
How To Insert Form Data Into Database Using Php ? – Geeksforgeeks

See more here: kientrucannam.vn

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *