<?php
$link = mysqli_init();
$db = mysqli_real_connect($link, 'localhost', 'bp6am', 'bp6ampass', 'expense_report') or
die('Unable to connect');
mysqli_select_db($link, 'expense_report');
?>
<html>
<head>
<title>Expenditure Log Form</title>
</head>
<body>
<form action="commit.php" method="post">
<table>
<tr>
<td>Name</td>
<td><input type="text" name="name"/><br></td>
</tr>
<tr>
<td>Category</td>
<td><select name="category">
<?php
//get the expenses categories
$query = 'SELECT cat_id, cat_name
FROM exp_category
ORDER BY cat_name';
$result = mysqli_query($query, $db) or
die(mysqli_connect_error($db));
//populate the dropdown menu for expenses category
while($row = mysqli_fetch_assoc($result)) {
foreach ($row as $value) {
echo '<option value="' . $row['cat_id'] . '">';
echo $row['cat_name'] . '</option>';
}
}
?>
</select></td>
</tr>
<tr>
<td>Amount</td>
<td><input type="text" name="amount"/></td>
</tr>
<tr>
<td>Payment Mode</td>
<td><select name="payment">
<?php
//retrieve and populate
$query = 'SELECT pay_id, pay_type
FROM pay_mode
ORDER BY pay_id';
$result = mysqli_query($query, $db) or
die(mysqli_connect_error($db));
//populate
while($row = mysqli_fetch_assoc($result)) {
foreach ($row as $value) {
echo '<option value="' . $row['pay_id'] . '">';
echo $row['pay_type'] . '</option>';
}
}
?>
</select></td>
</tr>
</table>
</form>
</body>
</html>
When I run the file in browser, only the Name field is constructed. After that there is the Category text with the select icon but no menu drops down on clicking it. Rest of the page is blank!! Recently started with PHP please help.
I'm wondering whether the connection is established or not. Even if no connection was established why other HTML elements are not being displayed after the Category field?
I checked my connection parameters. Even if they were wrong I should get the message "Unable to connect" right?