|
General Clean Up resets the |
Person Table |
Book Table |
Documentation |
||
|
Note - Create, Drop and Clean Up would be
hidden on a real life system. |
|||||
SELECT * FROM person WHERE last_name LIKE '%%' OR first_name LIKE '%%'
ID |
Title |
First Name |
Last Name |
DOB |
| 1 | Mr | Fred | Bloggs | 1992-12-27 |
| 2 | Ms | Mary | Jane | 1991-11-24 |
| 3 | Mr | John | Doe | 1982-05-09 |
Code Listing : personSearch.php |
<?php
$search_text = htmlentities($_POST['search_text']);
require "../MySQL_Login.php"; // Contains host, username, password, and database
$link = mysql_connect($host, $user, $password) or die(mysql_error());
mysql_select_db ($database) or die(mysql_error());
$sql =
"SELECT * FROM
person
WHERE
last_name LIKE '%$search_text%'
OR
first_name LIKE '%$search_text%'";
$result = mysql_query($sql, $link) or die(mysql_error());
mysql_close($link);
?>
<html>
<head>
<title>Search for a Person</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
include "nav.php";
echo"<font size=\"+2\"><b><pre>$sql</pre></b></font>";
?>
<form name="form1" method="post" action="">
<table border="1" cellpadding="4" cellspacing="0">
<tr>
<td><div align="right">Enter all or part of the first or last name</div></td>
<td>
<input name="search_text" type="text" id="search_text"
value="<?php echo $search_text; ?>">
</td>
</tr>
<tr>
<td colspan="2"><div align="right">
<input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
</table>
</form>
<table border="1" cellspacing="0" cellpadding="4">
<tr>
<td><h3>ID</h3></td>
<td><h3>Title</h3></td>
<td><h3>First Name</h3></td>
<td><h3>Last Name</h3></td>
<td><h3>DOB</h3></td>
</tr>
<?php
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo " <tr>\n";
echo " <td>" . $row['person_id'] . "</td>\n";
echo " <td>" . $row['title'] . "</td>\n";
echo " <td>" . $row['first_name'] . "</td>\n";
echo " <td>" . $row['last_name'] . "</td>\n";
echo " <td>" . $row['date_of_birth'] . "</td>\n";
echo " </tr>\n";
}
?>
</table>
<?php
include "dump.php";
dump_page(basename($_SERVER[SCRIPT_FILENAME])); // Display the code of this page
?>
</body>
</html>
|