Source
File - Form
<html>
<head>
<title>Form</title>
</head>
<body>
<h1>Rooms Data</h1>
<form
ACTION="getData.php" method=post>
<table border=0>
<tr>
<td>Room
No.</td>
<td
align="center"><input type="text" name="roomno" size="3" maxlength="3"></td>
</tr>
<tr>
<td colspan="2"
align="center"><br>
<input
type="submit" value="Get Data"></td>
</tr>
</table>
</form>
</body>
</html>
Source
file – ‘getdata.php’
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Room Data Retrieved</title>
</head>
<body style="font-family: Arial">
<h1>Data for room number <?php echo $_POST['roomno'] ?></h1>
<?php
$rno = $_POST['roomno'];
$db_server = "localhost";
$db_user = "root";
$db_pwd = ""; //Enter your root password here.
$db_name = "inventory"; //Replace mydata with the name of your database (inventory)
$tb_name = "room_inventory"; //Replace mytable with the name of your database (room_inventory)
$cnn = mysql_connect($db_server, $db_user, $db_pwd) or die (mysql_error());
mysql_select_db($db_name, $cnn) or die(mysql_error());
$query = "select * from " . $tb_name . " where Room = " . $rno;
$res = mysql_query($query, $cnn) or die(mysql_error());
while($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
$data[] = $row;
}
echo "<style>table.dump { font-family:Arial; font-size:12pt; }</style>";
echo "<table class=\"dump\" border=\"1\" cellpadding=\"1\" cellspacing=\"0\">\n";
echo "<tr>";
echo "<th>#</th>";
if(!isset($data)) {
echo "No Data available for room " . $rno;
exit(1);
}
foreach($data[0] as $key => $val) {
echo "<th><b>";
echo $key;
echo "</b></th>";
}
echo "</tr>\n";
$row_cnt = 0;
foreach($data as $row) {
$row_cnt++;
echo "<tr align='center'>";
echo "<td>".$row_cnt."</td>";
foreach($row as $val) {
echo "<td>" . $val . "</td>";
}
echo"</tr>\n";
}
echo "</table>\n";
?>
</body>
</html>