-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
79 lines (79 loc) · 2.79 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
include_once 'header.php';
if(isset($_POST['search_submit'])&$_POST['message_target']!='')
{
echo "<div class='table-title'>";
echo "<h3>Search Results of '".$_POST['message_target']."'</h3>";
echo "</div>";
try
{
$sequence = '%'.$_POST['message_target'].'%';
$search = "SELECT msg_id,msg, username,msg_time,uid
FROM messages, users
WHERE messages.uid = users.user_id AND msg LIKE ?
ORDER BY `messages`.`msg_time` DESC";
$stmt = $conn->prepare($search);
$stmt->bindValue(1,$sequence,PDO::PARAM_STR);
$stmt->execute();
if($stmt->rowCount()!=0)
{
echo "<div class='table-title'>";
echo "<h3>".$stmt->rowCount()." results:</h3>";
echo "</div>";
?>
<table class = "table-fill">
<tr><th id="text">Message</th>
<th id="name">By</th>
<th id="time">Time</th>
<th id="actions">Delete</th>
<?php
while($row=$stmt->fetch(PDO::FETCH_OBJ))
{
echo "<tr><td>".nl2br($row -> msg)."</td>";
echo "<td>".$row -> username."</td>";
echo "<td>".$row -> msg_time."</td>";
if($_SESSION['user']==$row->uid)
{
?>
<td id="actions">
<form action="home.php" method="POST" >
<button type="submit" id="del_btn" name="delete_action" value ="delete"
style="border:0;background transparent;"
onclick="return confirm('Delete this message?')"/>
<img style ="width:30px;height:30px;"src="delete.png" class = "invert" title = "Delete This Message" alt="submit" />
<?php
echo "<input type='hidden' name='del_msg_id' value=".$row->msg_id.">"
?>
</form>
</a>
</td>
<?php
}
else
{
echo "<td></td>";
}
echo"</tr>";
}
echo "</table><br>";
}
else
{
echo "<div class='table-title'>";
echo "<h3>No results!<br>Please review your input !</h3>";
echo "</div>";
}
}
catch(Exception $e)
{
die(var_dump($e));
}
}
else
{
echo "<div class='table-title'>";
echo "<h3>Error on search !<br>Please make sure that you had entered a valid input !</h3>";
echo "</div>";
}
?>
<a href="home.php" id="back_to_home">Go Back</a>