How to Sending Data to a Database php

How to Sending Data to a Database php

Save Data to a Database by php

The process of adding information to a table is similar
 to creating the table itself in terms of which functions
 you use, but the SQL query will be different.

$Query = "INSERT into $TableName values
 ('value1', 'value2', 'value3', etc.)";
mysql_db_query ("DatabaseName", $Query,

The query begins with INSERT into $TableName values. Then, within the parentheses, the value for each column should be put within single quotation marks with each value separated by a comma. There must be exactly as many values listed as there are columns in the table or else the query will not work! Then the query is submitted to the MySQL using mysql_db_query().

To demonstrate this, you'll use an HTML form that takes the user's first name, last name, E-mail address, and comments. The PHP script that handles this form will put the submitted information into the database.

To enter data into a database from an HTML form:

Create a new HTML document in your text editor that will create the HTML form.

Code the standard HTML header


Create a form.

<FORM ACTION="HandleForm.php"

Code for four text inputs.

 NAME="Array[LastName]" SIZE=40><BR>
 E-mail Address <INPUT TYPE=TEXT
 NAME="Array[Email]" SIZE=60><BR>
 Comments <TEXTAREA
 NAME="Array[Comments]" ROWS=5

You can make your form more attractive than this one but be sure to make note of your input variable names, which you'll need in the HandleForm.php page.

Add the submit button, close the form, and close the HTML page.


Save the page as form.html and upload it to the server.

Now you will write the HandleForm.php page, which takes the data generated by the form and puts it into the database.

Create a new PHP document in your text editor.