01 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 |
02 | Transitional//EN" |
03 | "http://www.w3.org/TR/html4/loose.dtd"> |
04 | <html> |
05 |
06 | <head> |
07 | <title>Form Input Data</title> |
08 | </head> |
09 |
10 | <body> |
11 | <table border="1"> |
12 | <tr> |
13 | <td align="center">Form Input Employees Data</td> |
14 | </tr> |
15 | <tr> |
16 | <td> |
17 | <table> |
18 | <form method="post" action="input.php"> |
19 | <tr> |
20 | <td>Name</td> |
21 | <td><input type="text" name="name" size="20"> |
22 | </td> |
23 | </tr> |
24 | <tr> |
25 | <td>Address</td> |
26 | <td><input type="text" name="address" size="40"> |
27 | </td> |
28 | </tr> |
29 | <tr> |
30 | <td></td> |
31 | <td align="right"><input type="submit" |
32 | name="submit" value="Sent"></td> |
33 | </tr> |
34 | </table> |
35 | </td> |
36 | </tr> |
37 | </table> |
38 | </body> |
39 | </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.
01 | <? |
02 | //the example of inserting data with variable from HTML form |
03 | //input.php |
04 | mysql_connect("localhost","root","admin");//database connection |
05 | mysql_select_db("employees"); |
06 |
07 | //inserting data order |
08 | $order = "INSERT INTO data_employees |
09 | (name, address) |
10 | VALUES |
11 | ('$name', |
12 | '$address')"; |
13 |
14 | //declare in the order variable |
15 | $result = mysql_query($order); //order executes |
16 | if($result){ |
17 | echo("<br>Input data is succeed"); |
18 | } else{ |
19 | echo("<br>Input data is fail"); |
20 | } |
21 | ?> |
After you have already made input.php, fill the input data and then click the sent button such as:
For the result:
As for the exercises, put some of datas into employees database.



Tidak ada komentar:
Posting Komentar