我编写了一个代码来将html页面连接到数据库,但它不会搜索表中的所有员工。我不确定为什么代码似乎是正确的。它不会给出任何错误或警告。
任何人都可以向我解释有什么问题吗?
<div>
<form id='searchform' action='index.php' method='get'>
<a href='index.php'>All employees</a> ---
Search by a last name:
<input id='search' name='search' type='text' size='20' value='<?php echo @$_GET['search']; ?>' />
<input id='submit' type='submit' value='Go!' />
</form>
</div>
<?php
// check if search view of list view
if (isset($_GET['search'])) {
$sql = "SELECT * FROM Employee WHERE LastName like '%" . @$_GET['search'] . "%'";
} else {
$sql = "SELECT * FROM Employee";
}
// execute sql statement
$stmt = oci_parse($conn, $sql);
oci_execute($stmt);
?>
<table style='border: 1px solid #DDDDDD'>
<thead>
<tr>
<th>Personal Number</th>
<th>Insurance Number</th>
<th>First Name</th>
<th>Last Name</th>
<th>Birth Date</th>
<th>Gender</th>
<th>Hire Date</th>
<th>Salary</th>
<th>Office ID</th>
</tr>
</thead>
<tbody>
<?php
// fetch rows of the executed sql query
while ($row = oci_fetch_assoc($stmt)) {
echo "<tr>";
echo "<td>" . $row['PersonalNumber'] . "</td>";
echo "<td>" . $row['InsuranceNumber'] . "</td>";
echo "<td>" . $row['FirstName'] . " " . $row['LastName'] . "</td>";
echo "<td>born on " . $row['BirthDate'] . "</td>";
echo "<td>" . $row['Gender'] . "</td>";
echo "<td>hired on " . $row['HireDate'] . "</td>";
echo "<td>" . $row['Salary'] . "</td>";
echo "<td>" . $row['OfficeID'] . "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
<div>There are found <?php echo oci_num_rows($stmt); ?> employees!</div>
<?php oci_free_statement($stmt); ?>
</body>