PHP MySQL: Creating Form Insert Data

php mysql basic step by step tutorial - part 9: In order to make this input data is 'user friendly', you can make a HTML form for input data, example:

<title>Form Input Data</title>

<table border="1">
    <td align="center">Form Input Employees Data</td>
        <form method="post" action="input.php">
          <td><input type="text" name="name" size="20">
          <td><input type="text" name="address" size="40">
          <td align="right"><input type="submit" 
          name="submit" value="Sent"></td>

The result:

php mysql form input data

This HTML form will send two variable, $name and $address variable, into input.php file as describe in the ACTION parameter of FORM HTML.

//the example of inserting data with variable from HTML form
mysql_connect("localhost","root","admin");//database connection

//inserting data order
$order = "INSERT INTO data_employees
			(name, address)

//declare in the order variable
$result = mysql_query($order);	//order executes
	echo("<br>Input data is succeed");
} else{
	echo("<br>Input data is fail");

After you have already made input.php, fill the input data and then click the sent button such as:

PHP mysql basic insert data

For the result:

PHP mysql basic insert data

If you see through phpmyadmin

php mysql insert data phpmyadmin

As for the exercises, put some of datas into employees database.

Series this article:
PHP MySQL: Connecting to Database Use mysql_connect()
PHP MySQL: Making Database Use mysql_create_db()
PHP MySQL: Making Table
PHP MySQL: The Data Type of Field
PHP MySQL: Char and Varchar Data Type
PHP MySQL: Data Type of Date
PHP MySQL: MySQL Syntax Orders
PHP MySQL: Inserting Data
PHP MySQL: Creating Form Insert Data
PHP MySQL: Display Data
PHP MySQL: mysql_fetch_row() Function
PHP MySQL: mysql_fetch_array() Function
PHP MySQL: Editing data
PHP MySQL: Deleting data
PHP MySQL: Adding Field Table
PHP MySQL: Editing Field Table
PHP MySQL: Deleting Field Table

Bookmark and Share Tag: mysql, database, insert, form, data Category: PHP Database Post : March 02nd 2008 Read: 424,896


blog comments powered by Disqus