我设置了搜索功能。当我输入关键字时,我得不到任何记录,也没有错误信息。只是表头。我在数据库中看到了其他部门。当我在关键字框中输入它时,我什么都没有回来。
<html>
<head>
<title></title>
</head>
<body>
<form name="frmSearch" method="get" action="">
<table width="599" border="1">
<tr>
<th>Keyword
<input name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $_GET["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<?php
if($_GET["txtKeyword"] != "")
{
$serverName = "localhost";
$objConnect = new PDO( "sqlsrv:server=$serverName ; Database=maintenance", "TestUser", "test") or die("Error Connect to Database");
// Search By lanId or department
$objQuery = $objConnect->prepare("SELECT * FROM requests WHERE (lanId LIKE '%".$_GET["txtKeyword"]."%' or department LIKE '%".$_GET["txtKeyword"]."%' ) ");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">lanId </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">department </div></th>
</tr>
<?php
while( $objResult = $objQuery->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><div align="center"><?php echo $objResult["lanId"];?></div></td>
<td><?php echo $objResult["name"];?></td>
<td><?php echo $objResult["department"];?></td>
<?php
}
?>
</table>
<?php
}
?>
</body>
</html>
答案 0 :(得分:0)
使用prepare()
语句时,您还应使用execute()
:
http://coursesweb.net/php-mysql/pdo-prepare-execute