phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP MySQL: Creating Form Insert Data

Tag: mysql, database, insert, form, data   Category: PHP Database
post: 02 Mar 2008 read: 4,158


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:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 
Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<title>Form Input Data</title>
</head>

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

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
//input.php
mysql_connect("localhost","root","admin");//database connection
mysql_select_db("employees");

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

//declare in the order variable
$result = mysql_query($order);	//order executes
if($result){
	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

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting