<?php
ini_set('display_errors', 1);
error_reporting(~0);
$strKeyword = null;
if(isset($_POST["txtKeyword"]))
{
$strKeyword = $_POST["txtKeyword"];
}
?>
<form name="frmSearch" method="post" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
<table width="599" border="1">
<tr>
<th>Keyword
<input name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $strKeyword;?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<?php
$serverName = "localhost";
$userName = "root";
$userPassword = "1234";
$dbName = "testdb";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
mysqli_set_charset($conn, "utf8");
$sql = "SELECT * FROM provider WHERE (NAME LIKE '%".$strKeyword."%' OR LNAME LIKE '%".$strKeyword."%' ) ";
$query = mysqli_query($conn,$sql);
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CID </div></th>
<th width="98"> <div align="center">NAME </div></th>
<th width="198"> <div align="center">LNAME </div></th>
<th width="198"> <div align="center">BIRTH </div></th>
</tr>
<?php
while($result=mysqli_fetch_array($query,MYSQLI_ASSOC))
{
?>
<tr>
<td><div align="center"><?php echo $result["CID"];?></div></td>
<td><?php echo $result["NAME"];?></td>
<td><?php echo $result["LNAME"];?></td>
<td><?php echo $result["BIRTH"];?></td>
</tr>
<?php
}
?>
</table>
<?php
mysqli_close($conn);
?>
ไม่มีความคิดเห็น:
แสดงความคิดเห็น