forked from vikassinghv34/Book_publish_Management_System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchback.php
42 lines (36 loc) · 1.41 KB
/
searchback.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
<?php
include('conn.php');
$term=$_REQUEST["term"];
$length=3;
if(isset($_REQUEST["term"]) && strlen($term)>=$length){
// Prepare a select statement
$sql = "SELECT * FROM books WHERE bookName LIKE ?";
if($stmt = mysqli_prepare($conn, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_term);
// Set parameters
$param_term ='%'. $_REQUEST["term"] . '%';
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
$result = mysqli_stmt_get_result($stmt);
// Check number of rows in the result set
if(mysqli_num_rows($result) > 0){
// Fetch result rows as an associative array
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
// echo "<p>" . $row["bookName"],$row["bookID"] . "</p>";
?> <p onClick="window.location='item.php?bookId=<?= $row["bookId"]?>'"> <?php echo $row["bookName"]?> </p><?php
// $_SESSION['searchid']=$row["bookID"];
}
} else{
echo "<p>No matches found</p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
}
}
// Close statement
mysqli_stmt_close($stmt);
}
// close connection
mysqli_close($conn);
?>