ชื่อฐานข้อมูล: tb_book
ฟิลด์ id_book int (11) AUTO_INCREMENT PRIMARY KEY
ฟิลด์ unit1 int (11) NOT NULL
ฟิลด์ unit2 int (11) NOT NULL
ฟิลด์ sum int (11) NOT NULL
 
FileName: connect.php

<?
$host="localhost";
$userdb="ceducat1_158html";
$passdb="xxxxxxxx";
$dbname="ceducat1_158html";

mysql_connect($host,$userdb,$passdb) or die ("Cannot User Connect");
mysql_select_db($dbname) or die ("Cannot DB Connect");

?>

 
FileName: form_add.html | Link: 

<html>
<head><title>Add Data</title></head>
<body>

<form name="form1" id="form1" method="POST" action="form_save.php">
Input Unit1:
<input name="txtUnit1" type="text" id="txtUnit1" /><p>
Input Unit2:
<input name="txtUnit2" type="text" id="txtUnit2" /><p>

<input type ="submit" name="submit" value="OK" />
</form>

</body>
</html>


 
FileName: form_save.php

<?
include ("connect.php");

$unit1 = $_POST[txtUnit1];
$unit2 = $_POST[txtUnit2];

$sum = $unit1 * $unit2 * 100;

$SQLinsert = "INSERT INTO tb_book (unit1,unit2,sum)
values('$unit1','$unit2','$sum')";

mysql_query($SQLinsert);
echo"Input Data Complete<br>";
mysql_close();

?>

 
FileName: view_data.php | Link: แบบที่ 1

<?
include("connect.php");
$SQLselect = "select * from tb_book";
$SQLresult = mysql_query($SQLselect) or die (mysql_error());

while($show = mysql_fetch_array($SQLresult))
{
echo "ID".$show['id_book'];
echo "Unit1".$show['unit1'];
echo "X";
echo "Unit2".$show['unit2'];
echo "=".$show['sum'];
echo "<br>";
}
mysql_close();
?>


 
FileName: view_data.php | Link: แบบที่ 2

<body>
<?
include("connect.php");
$SQLselect = "select * from tb_book";
$SQLresult = mysql_query($SQLselect) or die (mysql_error());
?>
<table width="80%" border="1">
<tr><td>ID</td><td>Unit1</td><td>X</td><td>Unit2</td><td>=</td><td>Sum</td></tr>

<?
while($show = mysql_fetch_array($SQLresult))
{
echo "<tr>" ;
echo "<td>"."ID".$show['id_book']."</td>";
echo "<td>".$show['unit1']."</td>";
echo "<td>"."X"."</td>";
echo "<td>".$show['unit2']."</td>";
echo "<td>"."="."</td>";
echo "<td>".$show['sum']."</td>";
echo "<br>";
echo "</tr>";
}
mysql_close();
?>
</table>
</body>