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 :
-
- Install the Xampp server in your machine and if it already installed just go to xampp -> htdocs folder .
-
- Create a new folder say addemp in the htdocs folder.
-
- In this addemp folder create a new file say index.php and open it with Notepad++ or any other text editor.
-
- Now for designing a form write the given code in index.php file .
<!DOCTYPE html> <html> <head> <style> label{display:inline-block;width:100px;margin-bottom:10px;} </style> <title>Add Employee</title> </head> <body> <form method="post" action=""> <label>First Name</label> <input type="text" name="first_name" /> <br /> <label>Last Name</label> <input type="text" name="last_name" /> <br /> <label>Department</label> <input type="text" name="department" /> <br /> <label>Email</label> <input type="text" name="email" /> <br /> <input type="submit" value="Add Employee"> </form> </body> </html>
-
- The screenshots for Notepad++ window are shown below :
-
- Now go to xampp control pannel and start the Apache and MySQL modules .
-
- Now to run your program enter the following url in the browser http://localhost/addemp/index.php and you will have the following output :
-
- Now to have a view of the inserted data just create a new file called as process.php in the same addemp folder .
-
- Write the code in process.php file
<?php echo $_POST['first_name']; echo '<br />'; echo $_POST['email'];
-
- So you will have the following view of your Notepad++ window :
-
- 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) .
-
- Now to show all the data fields present in the html form , replace the code of process.php file with the given code :
<?php print_r($_POST);
-
- Here is the screen shot of Notepad++ window :
-
- Now run the index.php file and insert data in to the html form :
-
- 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 :
-
- In our example , we need to get connected with the MySQL database , so let’s modify the process.php file .
-
- Now write the given code in the process.php file.
<?php include 'database.php';> <?php // create a variable $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; $department=$_POST['department']; $email=$_POST['email']; //Execute the query mysqli_query($connect"INSERT INTO employees1(first_name,last_name,department,email) VALUES('$first_name','$last_name','$department','$email')");
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.
-
- To create a database connection we have to create new file say database.php in the same addemp folder.
-
- You will have the following view :
-
- Now open the database.php file in Notepad++ or any other text editor and write the given code :
<?php $connect=mysqli_connect('localhost','root','123','mydatabase'); if(mysqli_connect_errno($connect)) { echo 'Failed to connect'; } ?>
-
- You will have the following view of your Notepad++ window :
-
- 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.
-
- So add the data and click the Add Employee button :
-
- If you run the process.php file it will display the blank window which means your data has been inserted into the database .
-
- Now check your created employee table in the database in the phpmyadmin pannel :
-
- Now to display the content in the browser , we have to add code that will check the if added condition :
-
- So add the given code in the process.php file .
<?php include 'database.php'; ?> <?php // create a variable $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; $department=$_POST['department']; $email=$_POST['email']; //Execute the query mysqli_query($connect,"INSERT INTO employees1 (first_name,last_name,department,email) VALUES ('$first_name','$last_name','$department','$email')"); if(mysqli_affected_rows($connect) > 0){ echo "<p>Employee Added</p>"; echo "<a href="index.html">Go Back</a>"; } else { echo "Employee NOT Added<br />"; echo mysqli_error ($connect); }
-
- ScreenShot of Notepad++ window is shown below :
-
- After inserting the data in the index.php file click the AddEmployees button we will be navigated to the process.php file.
-
- So if the data is inserted into the the database you will have the following window otherwise it will display an error message:-
-
- 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.
-
- When we click on the GoBack link it will link to the index.php file.
-
- Thus you will be navigated to the index.php file .
- Thus we have learnt to insert the data into the MySQL database by designing an html form and connecting the database using php.
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
From what I’ve read the only difference between the html and php extensions are the extension themselves in other words you can have a php file that contains onlt html and vise versa. The big reason to use a php file extension is so as a developer you know that file contains php code. I like masking the files that contain php so that when I call them the user is not alerted to one I’m on a lennox server and two this file my contain code which can be hacked if you are good with php.
There are some mistakes here, but the majority of your code is ok. Thank you for this tutorial.
its not working please help me improve
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?
sme problem here. can u share the answer to the problem
just enter action=”process.php” in the form in index.php
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
Hi,
In the index.php file, in the line 13, please change line to
Save again index.php, open it and and should work.
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!
I am not clear about the section…….
Learn to submit HTML data to MySQL database using php
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
it is in windows 7. if any have knowledge about this plz explain it .
Its a good Website for learning programming
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.
put it in comment section if you are getting errot
I am getting the error below after putting a comment section
Notice: Undefined index: first_name in C:\xampp\htdocs\addemp\process.php on line 6
Notice: Undefined index: last_name in C:\xampp\htdocs\addemp\process.php on line 7
Notice: Undefined index: department in C:\xampp\htdocs\addemp\process.php on line 8
Notice: Undefined index: email in C:\xampp\htdocs\addemp\process.php on line 9
Parse error: syntax error, unexpected ‘;’ in C:\xampp\htdocs\addemp\process.php on line 1
This page certainly has all the info I needed concerning this subject and didn’t know who
to ask.
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?
Please send complate tutorial on connection of html to database
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
not work
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.
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 "
I’m experiencing the same errors.. How does one fix them… I have done precisely what he wrote
Try to add the page name process.php in action like below
this should solve this issue.
Good concept regarding “How to insert data into database from HTML form”.
Thank you very much for this query. Finally……..
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
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
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
Can someone answer this? Im also having a problem with here
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!
This info is priceless. How can I find out more?|
I have recently started a web site, the info you provide on this web site has helped me greatly. Thanks for all of your time & work.
Just wanna input on few general things, The website layout is perfect, the written content is very good : D.
Thank you so very much! It took me hours to get it to work (mistakes here and there) but I think I learned a lot on the way. All the best to you.
Thanks, this website is really useful.|
Thanks, this site is really useful.|
Hello Dear ,
I have just visit your blog & found your blog’s post are very useful . I like Your every post because you have discussed what I am looking for . Thank you For your nice posting . I hope That You will be continuing this kind of posting .
Hello there, You have done a great job. I’ll definitely digg it and personally recommend to my friends. I’m confident they’ll be benefited from this web site.
I conceive you have mentioned some very interesting points, appreciate it for the post.
Hi there, great web site you have here.|
Parse error: syntax error, unexpected ‘index’ (T_STRING), expecting ‘,’ or ‘;’ in C:\xampp\htdocs\login\process.php on line 19
Hi there very nice site!! Guy .. Beautiful .. Amazing .. I will bookmark your web site and take the feeds additionally…I am glad to find numerous useful info right here in the submit, we’d like work out more strategies in this regard, thanks for sharing.
Hello to every body, it’s my first pay a quick visit of this website; this website carries awesome and truly excellent data for visitors.|
You have got among the best websites.|
I¡¦ve recently started a site, the info you provide on this web site has helped me greatly. Thanks for all of your time & work.
Nice
$myname = mysqli_real_escape_string($db,$_POST[‘nameg’]);
for this,it is displaying Undefined variable: myname in C:\xampp\htdocs\gphp.php on line 15
how to resolve this??
Very nice tutoriel !
This post will help the people who are looking to build up new website or even a weblog from start to end.
I’d like to fknd out more?I’d love to find out some additional information.
im trying
Hey great post! I hope it’s alright that I shared it on my Twitter, if not,
no problem just tell me and I’ll delete it. Regardless keep up the
great work.
Wonderful simple tut. easy to follow and understand.
Thank you v.much.
Thanks , I have just been searching for information approximately
this subject for a long time and yours is the greatest I have came upon till now.
But, what in regards to the bottom line? Are you sure about the supply?
Geat post.
when i submit, no data is posted and no error is shown
I have read so many articles concerning the blogger lovers however this
article is actually a nice article, keep it up.
As I follow your instructions and steps as follows It worked well for me. If you face any issue in hp services you can visit us at our site.
As the guidelines mentioned in your post to submit HTML data to MySql database are nice to follow.
i tried following your tutorial but my php codes are not executed well
when i tried to run this is what happened. please help me with this.
Parse error: syntax error, unexpected ‘>’, expecting end of file in C:\xampp\htdocs\project\process.php on line 2
delete side one we can get the output
Your process.php has some problem, I think form php is not link with process.php. In process.php always show
”
Notice: Undefined index: first_name in C:\xampp\htdocs\process.php on line 3
Notice: Undefined index: email in C:\xampp\htdocs\process.php on line 5
“
More code please on how to UPDATE, DELETE and RETRIEVE data from database table
Thanks a lot
how we are getting output for process.php
nothing I can fouund
i too am a student . my localhost server doesnt processphp file rather it displaysall the code as it is .how to fix this .i will be grateful to who answer it .
help me
where to add the process.php on index.php
thanks for this now i can combine the php html and database
Must be growing old, took me 3 days to get it to work. Thanks for tutorial was quite helpful.
how did you connect the button ‘Add Employee’ to your php code
Hai, can I know how to send data using php without tag form method by clicking specified button ???
Hi albert, Greetings!
If you properly created the table(employees1) inside the database(mydatabse) then it should work with below codding as per the nice guide lines given by the Author in this tutorial…….!!!
Cheers!
Very shortly this web page will be famous amid all blog visitors,
due to it’s pleasant articles
how can i run apache and mysql modules in wamp server