Create contact form fields or survey form and insert data into MySQL database using PHP


In you want to make a contact form or you want to make a survey and data to be sent to a MySQL database using PHP, you need to follow some basic steps .

First you need to have support for PHP (Apache web server) and a MySQL database (PHPMyAdmin best for managing). For local use you can download Xampp and for web usage Cpanel is the easiest way to do it .

After you have support for PHP and database, and web server in place up and running, you need to create a database in PHP my admin with the fields you want for inserting data (text type) and you also can create a integer type for a unique number (make it primary key) and a timestamp for adding a date and time to a field to see when was inserted in database .

Now you need to create PHP three files . A index file where the form will be, a show file where you can see the data in database and a insert file which will insert the data in database after you hit the send button from the form .

So in the index file (called index.php) you need to enter the form fields .
So you have four text fields that will send data to your database columns .
I will also show you in the insert file how to create a time filed to be sent to database .

Download index file

Now in the insert file (called insert.php) you need to enter the PHP variables . We will use the mysqli function since the MySQL function is deprecated in the newer version of PHP .

Download insert file

Now in the show.php file where you can see the data from the database .

Download show file

That’s it, now you have three php files, one has the form fields, one inserts data into the database, one reads and shows data from the database !

If the files rpovided you have also comments for all stuff.

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Lost Password