Submit HTML Form Data Values to Mysql Database in PHP

By | August 17, 2012

Submit HTML Form Data / Values to Database in PHP | Submit HTML/PHP Form data/values in Database 






In this tutorial we will discuss about Submitting the HTML Form or PHP Form in the Database first we will submit it without the use of Jquery which will refresh the page  after that we will implement the Jquery for submitting the value without refreshing the page in next tutorial.

Let’s Start 🙂

Steps to complete this tutorial.

Step 1. We will make an HTML Form.

Step 2. We will define HML Form Action to PHP Page

Step 3. Making Database.

Step 4. PHP page to Read Form values in Save the Values.

Step 5. Submitting the value to the PHP Page

Step 1. Making HTML Form

Here we will write the code to make the html form. We will use the table here to make the form. We use only 2 fields and 1 submit button.

This is your form will look like and now we will make the link of this form to our PHP page.

Step 2. Form action to PHP Page

So we have done the HTML form earlier now we will send our values to PHP page.

Suppose we have PHP page named getValues.php. Now we will define the action in our HTML Form.

We will replace the above <form> code with this line of code

other code will remain same. Now why we change this and why we add these attributes. So let me tell you one by one.

1. Action=getvalue.php – When we will press the submit button this action will take our values to PHP page that is getValue.php.

2. Method=post – Right now i just tell you a little bit about this. When we us post than the URL will not show the parameters but the values are still there in the memory. We can use the “get” on the place of “post”. Get will show your values in the url parameter while checking the login information we always use the “Post”.

So here we finishes with the Action attribute of Form

 

 Step 3. Making Database.

Now after the HTML form and action attribute we have our values now what to do with these values. Lets play some tic tac toe or football with the values…. Lol …… We will make a Container to hold these values and save them. For saving the values we have many options like Array/Session (But will not retain your value after your browser closes), Cookies (Not a good idea there is a limit and if you change your pc it will show error), XML, Database. So here we will use the Database option and we use the mySql for this.

First of all we will create a database and name it myinformation.

Now will make the table

we will use 2 column here in table these are Firstname,Lastname.



Now we have completed our database structure and we will now move to our next step that is making our PHP page.

 Step 4. PHP page to save the values.

Now we will make our PHP page to get the HTML Form values and save them in our Database. First we will get the values.

From above code we will get the Form Values in these variables. $Firstname will put the firstname value and $lastname will put the lastname value.

If we use the GET at our HTML form than we will change the POST to GET.

Now we will Establish the connection with our database client to connect our database.

Now we have completed writing of PHP page which include the code to get the values from HTML Form and save them to the Database.

Step 5. Submitting the value to the PHP Page

Waiting for what ???? we have completed everything just try your code and see weather it is working or not. If there is any bug than let us know we will try to remove it.

Fill your form and press submit and see will it save or not.

Thank You for reading this article. Happy Coding.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.