01.
<html>
02.
<head>
03.
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
04.
</head>
05.
<body>
06.
<form name=
"frmSearch"
method=
"get"
action=
"<?=$_SERVER['SCRIPT_NAME'];?>"
>
07.
<table width=
"599"
border=
"1"
>
08.
<tr>
09.
<th>Keyword
10.
<input name=
"txtKeyword"
type=
"text"
id=
"txtKeyword"
value=
"<?=$_GET["
txtKeyword
"];?>"
>
11.
<input type=
"submit"
value=
"Search"
></th>
12.
</tr>
13.
</table>
14.
</form>
15.
<?
16.
if
(
$_GET
[
"txtKeyword"
] !=
""
)
17.
{
18.
$objConnect
= mysql_connect(
"localhost"
,
"root"
,
"root"
)
or
die
(
"Error Connect to Database"
);
19.
$objDB
= mysql_select_db(
"mydatabase"
);
20.
21.
$strSQL
=
"SELECT * FROM customer WHERE (Name LIKE '%"
.
$_GET
[
"txtKeyword"
].
"%' or Email LIKE '%"
.
$_GET
[
"txtKeyword"
].
"%' )"
;
22.
$objQuery
= mysql_query(
$strSQL
)
or
die
(
"Error Query ["
.
$strSQL
.
"]"
);
23.
?>
24.
<table width=
"600"
border=
"1"
>
25.
<tr>
26.
<th width=
"91"
> <div align=
"center"
>CustomerID </div></th>
27.
<th width=
"98"
> <div align=
"center"
>Name </div></th>
28.
<th width=
"198"
> <div align=
"center"
>Email </div></th>
29.
<th width=
"97"
> <div align=
"center"
>CountryCode </div></th>
30.
<th width=
"59"
> <div align=
"center"
>Budget </div></th>
31.
<th width=
"71"
> <div align=
"center"
>Used </div></th>
32.
</tr>
33.
<?
34.
while
(
$objResult
= mysql_fetch_array(
$objQuery
))
35.
{
36.
?>
37.
<tr>
38.
<td><div align=
"center"
><?=
$objResult
[
"CustomerID"
];?></div></td>
39.
<td><?=
$objResult
[
"Name"
];?></td>
40.
<td><?=
$objResult
[
"Email"
];?></td>
41.
<td><div align=
"center"
><?=
$objResult
[
"CountryCode"
];?></div></td>
42.
<td align=
"right"
><?=
$objResult
[
"Budget"
];?></td>
43.
<td align=
"right"
><?=
$objResult
[
"Used"
];?></td>
44.
</tr>
45.
<?
46.
}
47.
?>
48.
</table>
49.
<?
50.
mysql_close(
$objConnect
);
51.
}
52.
?>
53.
</body>
54.
</html>