-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
47 lines (41 loc) · 1.51 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
<?php
include("db.php");
//echo "<link rel=stylesheet type=text/css href=mystylesheet.css>";
$output='';
if(isset($_POST['search'])) {
$search = $_POST['search'];
$search2 = preg_replace("#[^0-9a-z]#i","",$search);
$SQL="SELECT * FROM product WHERE prodName LIKE '%$search2%'";
$exeSQL=mysqli_query($conn, $SQL) or die (mysqli_error());
$count = mysqli_num_rows($exeSQL);
if($count == 0){
$output = 'There was no search results !';
}else{
echo "<form action=search.php method=POST>";
echo "<input type='text' name='search' placeholder='Search'>";
echo "<button type='submit' name='submit' value='Search'>Search</button>";
echo "</form>";
echo "<form action=search.php method=POST>";
echo "<select name=item>";
while($arrayp=mysqli_fetch_array($exeSQL)){
$pid=$arrayp['prodId'];
echo "<option value=$pid>".$arrayp['prodName']."</option><br>";
}
echo "</select>";
echo "<input type=submit name=submit value='ADD TO BASKET'>";
//pass the product id to the next page basket.php as a hidden value
echo "<input type=hidden name=h_prodid value=".$pid.">";
echo "</form>";
}
}
if(isset($_POST['prodId'])){
echo $_POST['prodId'];
echo $_POST['h_prodid'];
}
if(!(isset($_POST['search']))){
echo "<form action=search.php method=POST>";
echo "<input type='text' name='search' placeholder='Search'>";
echo "<button type='submit' name='submit' value='Search'>Search</button>";
echo "</form>";
}
?>