when I run the search script I'm getting the following error Trying to get property of non-object in C:\xampp\htdocsesults.php on line 32 Why is it telling me it is not an object? It obviously gives a similar error on line 47. I would appreciate any help. Thank you
7<?php
8 // create short variable names
9 $searchtype=$_POST['searchtype'];
10 $searchterm=trim($_POST['searchterm']);
11
12 if (!$searchtype || !$searchterm) {
13 echo 'You have not entered search details. Please go back and try again.';
14 exit;
15 }
16
17 if (!get_magic_quotes_gpc()){
18 $searchtype = addslashes($searchtype);
19 $searchterm = addslashes($searchterm);
20 }
21
22 @ $db = new mysqli('localhost', 'printfactory0', '*********', 'printfactory');
23
24 if (mysqli_connect_errno()) {
25 echo 'Error: Could not connect to database. Please try again later.';
26 exit;
27 }
28
29 $query = "select * from printfactory where ".$searchtype." like '%".$searchterm."%'";
30 $result = mysqli_query($db, $query);
31
32 $num_results = $result->num_rows;
33
34 echo "<p>Number of products found: ".$num_results."</p>";
35
36 for ($i=0; $i <$num_results; $i++) {
37 $row = $result->fetch_assoc();
38 echo "<p><strong>".($i+1).". Product Name: ";
39 echo htmlspecialchars(stripslashes($row['ProductName']));
40 echo "</strong><br />Product Description: ";
41 echo stripslashes($row['Product_Description']);
42 echo "<br />Price: ";
43 echo stripslashes($row['Unit_Price']);
44 echo "</p>";
45 }
46
47 $result->free();
48 $db->close();
49
50?>