-
Notifications
You must be signed in to change notification settings - Fork 1
/
search2.php
61 lines (53 loc) · 1.7 KB
/
search2.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
<?php
include 'header.php';
?>
<select onChange="window.location.href=this.value">
<option value="search2.php">Escape String</option>
<option value="search.php">Vulnarable</option>
<option value="search3.php">Escape with Int</option>
<option value="search4.php">Escape with int conv</option>
<option value="s_search.php">Secured</option>
</select>
<form action="search2.php" method="POST">
<input type="text" name="search" placeholder="search trainers..">
<button type="submit">Find</button>
</form>
<h1> Search Page </h1>
<h3> Escape string used for string value here but may be injectable </h3>
<div class="shopping-container">
<table border="3" cellspacing="0" cellpadding="10">
<tbody>
<tr>
<th>Title</th>
<th>Description</th>
<th>Quantity</th>
</tr>
<?php
if(isset($_POST['search'])){
//real_escape_string may avoid sql injection
$search= mysqli_real_escape_string($conn,$_POST['search']);
if(empty($search)){
echo "Please fill in the search bar";
exit();
}
$sql ="SELECT * FROM shopping WHERE title LIKE '%$search%'";
print "<p> $sql </p>";
print "<hr>";
$result = mysqli_query($conn, $sql);
$queryResult = mysqli_num_rows($result);
echo "There are ".$queryResult." results! ";
if($queryResult > 0){
while($row = mysqli_fetch_assoc($result)){
echo "<tr><td>".$row["title"]."</td>";
echo "<td>".$row["description"]."</td>";
echo "<td>".$row["quantity"]."</td>";
}
}
}
?>
</tbody>
</table>
</div>
<div>
<p>@Computer Security Project <a target="_blank" href="http://www.eecs.qmul.ac.uk/"> www.eecs.qmul.ac.uk </a></p>
</div>