In this session we will design an html form ,add the data into it and submit it to the database by connecting it to MySQL database using php .

  • To design the html form follow the steps given below :

 

    1. Install the Xampp server in your machine and if it already installed just go to xampp -> htdocs folder .

 

    1. Create a new folder say addemp in the htdocs folder.

 

    1. In this addemp folder create a new file say index.php and open it with Notepad++ or any other text editor.
1
    1. Now for designing a form write the given code in index.php file .

 

 

    1. The screenshots for Notepad++ window are shown below :
v2
    1. Now go to xampp control pannel and start the Apache and MySQL modules .

 

    1. Now to run your program enter the following url in the browser http://localhost/addemp/index.php and you will have the following output :
v3
    1. Now to have a view of the inserted data just create a new file called as process.php in the same addemp folder .
v4
    1. Write the code in process.php file

 

 

    1. So you will have the following view of your Notepad++ window :
v5
    1. Now when you run the process.php file , the data that you had inserted in the html form will get displayed .


Note: It will display only FirstName and Email(As we have mentioned only the first name and email in the code) .

    1. Now to show all the data fields present in the html form , replace the code of process.php file with the given code :

 

 

    1. Here is the screen shot of Notepad++ window :
v7
    1. Now run the index.php file and insert data in to the html form :
v8
    1. After inserting the data click on the add button which will pass this data to the process.php file and when you run the process.php file you will get the following output :
v9
    1. In our example , we need to get connected with the MySQL database , so let’s modify the process.php file .

 

    1. Now write the given code in the process.php file.

 

Note:-Here we had included the database.php file at the beginning in the code to get connected with the database.
In the process.php file we have to add the insert query to add the record in our database.

    1. To create a database connection we have to create new file say database.php in the same addemp folder.

 

    1. You will have the following view :
v10
    1. Now open the database.php file in Notepad++ or any other text editor and write the given code :

 

 

    1. You will have the following view of your Notepad++ window :
v11
    1. After creating the database connection , run the index.php file insert the data into it , this data will get added into your database which is present in the phpmyadmin of the Xampp.

 

    1. So add the data and click the Add Employee button :
v12
    1. If you run the process.php file it will display the blank window which means your data has been inserted into the database .
v13
    1. Now check your created employee table in the database in the phpmyadmin pannel :
v14
    1. Now to display the content in the browser , we have to add code that will check the if added condition :

 

    1. So add the given code in the process.php file .

 

 

    1. ScreenShot of Notepad++ window is shown below :
v15
    1. After inserting the data in the index.php file click the AddEmployees button we will be navigated to the process.php file.

 

    1. So if the data is inserted into the the database you will have the following window otherwise it will display an error message:-
v16
    1. In the code section of the process.php file we have added the link from where we can go back to the index.php file to add the record of the employee in the database.

 

    1. When we click on the GoBack link it will link to the index.php file.

 

    1. Thus you will be navigated to the index.php file .
v17
  1. Thus we have learnt to insert the data into the MySQL database by designing an html form and connecting the database using php.
Learn to submit HTML data to MySQL database using php was last modified: by

Facebook Comments

Website Comments

  1. eban emmanuel
    Reply

    goodday my name is eban emmanuel am a student in ghana. ive been learning html5 and ive got little issues with creating a form when creating a form in html5 the form webpage must it be stored as .php or can i store it as a html and connect with a phpscript connecting to my xamp database ..really need this for ma project will be glad to hear back from you

  2. Webbience
    Reply

    Nice Form Data submission tutorial. If you provided a sample to store form data (comment) in text file and refresh the html page on submission and display the comment instantly. Thanks.

  3. johnny
    Reply

    There are some mistakes here, but the majority of your code is ok. Thank you for this tutorial.

    • Will
      Reply

      Agreed Johnny. A few too many I think.
      The most glaring is action=”” instead of action=”process.php”

  4. Chorpher
    Reply

    I typed process.php but when I run it it is not working, it show me that

    Notice: Undefined index: first_name in C:\xampp\htdocs\addemp\process.php on line 3

    is there something i lost?

  5. ayya
    Reply

    I make HTML web on my computer desktop after that i installed xampp and xampp -> htdocs folder i make login php so, my question is that do i need to make index.php on it or not if so how about html that i created on desktop.that index.html also i have to move on xampp -> htdocs folder

    • Tania
      Reply

      Hi,
      In the index.php file, in the line 13, please change line to
      Save again index.php, open it and and should work.

  6. Scotty
    Reply

    Hello there, I do believe your site could be having browser compatibility
    problems. Whenever I take a look at your web site in Safari, it looks fine however, if opening in Internet Explorer, it’s got some overlapping issues.
    I merely wanted to provide you with a quick heads up!
    Besides that, fantastic site!

  7. pradeep
    Reply

    I am not clear about the section…….
    Learn to submit HTML data to MySQL database using php

  8. kamlesh
    Reply

    These problem dedected in xampp control panel ? plz give me it’s solution. plz sir

    11:56:14 AM [mysql] MySQL Service detected with wrong path
    11:56:14 AM [mysql] Change XAMPP MySQL and Control Panel settings or
    11:56:14 AM [mysql] Uninstall/disable the other service manually first
    11:56:14 AM [mysql] Found Path: C:\xampp\mysql\bin\mysqld –defaults-file=C:\xampp\mysql\bin\my.ini mysql
    11:56:14 AM [mysql] Expected Path: c:\xampp\mysql\bin\mysqld.exe –defaults-file=c:\xampp\mysql\bin\my.ini mysql

  9. Bramhananda |Reddy
    Reply

    When I followed the series of steps you given above, I got an error message like this:
    Parse error: syntax error, unexpected ‘index’ (T_STRING), expecting ‘,’ or ‘;’ in C:xampphtdocsaddempprocess.php on line 19.
    Kindly get me the rectification for the above error.

  10. Amir
    Reply

    Parse error: syntax error, unexpected ‘;’ in C:\xampp\htdocs\addemp\process.php on line 1

  11. reinigungsunternehmen
    Reply

    This page certainly has all the info I needed concerning this subject and didn’t know who
    to ask.

  12. aclu-san-diego
    Reply

    I feel this is one of the such a lot vital information for me.
    And i’m satisfied studying your article. But should statement on some general issues,
    The site taste is great, the articles is in reality excellent : D.
    Excellent job, cheers

  13. Ekom etuk
    Reply

    I am a student of imfi ict academy uyo, please How can i partition my site to have many columns and rows without using table?

  14. john colt
    Reply

    Guys Help this is my process.php

    and this is my index.php

    label
    {
    display:inline-block;
    width:150px;
    margin-bottom:10px;
    }

    Add Applicant

    Add Applicant

    First Name:

    Last Name:

    Passport Number:

    Date of Birth:

    Place of Issue:

    Date of Expiration:

    Email:

    and my database.php

    but it does not connect or save to my data base. Am i doing something wrong. please help

  15. ubot
    Reply

    I think that what you said made a lot of sense. However, what about this?
    what if you composed a catchier post title? I mean, I don’t wish to tell you how to run your blog, however what if you added
    a post title that makes people want more? I mean Learn to submit HTML data
    to MySQL database using php is kinda vanilla.

    You should look at Yahoo’s front page and watch how they write
    news headlines to get people interested. You might add a related video or a related pic or two to
    get readers interested about everything’ve written. Just my opinion, it might bring
    your posts a little bit more interesting.

  16. gaurav adhav
    Reply

    I have to make a website in html.
    In which if the staff name and password correct then he can add documents.
    So how to make database and how can I connect with it with HTML file.

  17. Antonina
    Reply

    1st
    in process.php in the first two printscreens you don’t close the php it supposed to be like that? if yes then i have error when i’m running this file:
    Notice: Undefined index: first_name in C:xampphtdocsaddempprocess.php on line 4
    Notice: Undefined index: email in C:xampphtdocsaddempprocess.php on line 6

    2nd
    in the modification of process.php
    “<?php
    print_r($_POST); "
    my output is this: "Array ( ) "

    3rd
    You don't mention to create a database; what records, what data type … these infos are missing from the first steps when you first tell to open phpmyadmin to see the results!

    1st
    in process.php in the first two printscreens you don't close the php it supposed to be like that? if yes then i have error when i'm running this file:
    Notice: Undefined index: first_name in C:xampphtdocsaddempprocess.php on line 4
    Notice: Undefined index: email in C:xampphtdocsaddempprocess.php on line 6

    2nd
    in the modification of process.php
    "<?php
    print_r($_POST); "
    my output is this: "Array ( ) "

    3rd
    You don't mention to create a database; what records, what data type … these infos are missing from the first steps when you first tell to open phpmyadmin to see the results!
    4th
    in last insertion of data after executin index and then going to process.php
    " Parse error: syntax error, unexpected 'index' (T_STRING), expecting ',' or ';' in C:xampphtdocsaddempprocess.php on line 19 "

  18. P'jones
    Reply

    Please folks, I’m just taking programming as a career and I’m loving it despite discovering the tasking part of it. For this I’m beginning with web design and development, still a fresher in it I can say I am, but believing persistent practice makes perfect. Now, the issue I’m facing is, I added password to my MySQL from the console and I discovered my phpMyAdmin shows me error anytime I try to access it. Please, any idea to come out of this will be highly appreciated. WampServer is what I use for more certainty in proffering solution. Thank you

  19. santhosh
    Reply

    guys help me to find a solution for this problem:
    i have an php document with html form
    and i have date formated textbox
    i want to upload that data into the database using php

  20. gagan negi
    Reply

    Parse error: syntax error, unexpected ‘>’ in C:\xampp\htdocs\addemp\process.php on line 1
    this error is displayed for process.php file . please give me the solution for this

  21. Christina Granvil
    Reply

    That is the proper weblog for anyone who wants to search out out about this topic. You realize so much its virtually exhausting to argue with you (not that I actually would want…HaHa). You undoubtedly put a brand new spin on a subject thats been written about for years. Great stuff, simply great!

Post a comment