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:
This HTML form will send two variable, $name and $address variable, into input.php file as describe in the ACTION parameter of FORM HTML
<?php
//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:
For the result:

If you see through phpmyadmin
As for the exercises, put some of data’s into employees database.

0 comments:

Post a Comment

 
Top
Blogger Template