Telechargé par Kawthar Mtawaa

7. PHP MySQL - Search

publicité
PHP and MySQL
Address Book
conn.php
search.php
user
default.html
update.php
insert.php
edit.php
mydb
view.php
id
user_name
user_email
user_phone
delete.php
<form action="search.php" method="post">
<input type="text" name="search_key"/> <input type="submit" value="Search"/>
</form>
<?php
include("conn.php");
search.php
$search_key = isset($_POST['search_key']) ? $_POST['search_key'] : '';
if ($search_key == NULL)
{
echo "Please enter your search key";
}
else
{
$result = mysqli_query($con,"SELECT * FROM user WHERE user_name LIKE '%" . $search_key . "%'");
?>
<br/>
<table width="50%">
<tr bgcolor="#CC99FF">
<td>Name</td>
<td>Email</td>
<td>Phone Number</td>
<td>Edit</td>
<td>Delete</td>
Continue next page >>
</tr>
search.php
<?php
while($row = mysqli_fetch_array($result))
{
echo "<tr bgcolor=\"#99FF66\">";
echo "<td>";
echo $row['user_name'];
echo "</td>";
echo "<td>";
echo " <a href=\"mailto:" . $row['user_email']. "\">". $row['user_email'] . "</a> ";
echo "</td>";
echo "<td>";
echo $row['user_phone'];
echo "</td>";
echo "<td><a href=\"edit.php?id=".$row['id']."\">Edit</a></td>";
echo "<td><a href=\"delete.php?id=".$row['id']."\" onClick=\"return confirm('Delete This
account?');\">Delete</a></td>";
echo "</tr>";
}
mysqli_close($con);
}
?>
</table>
Sample Output
Sample Output
Téléchargement