Hello Folks,
Thanks for your responses and suggestions tomy problems. I have been trying to solve the problem on my own but it is not over yet and I will appreciate further help please.
The code that I am using for both files are pasted below.
Code:
<html>
<head>
<title>Boys and Babes cars</title>
</head>
<body>
<h2>Boys and Babes cars</h2>
<form action="results.php" method="post">
Choose Search Type:<br />
<select name="searchtype">
<option value="car">Car</option>
<option value="make">Make</option>
<option value="year">Year</option>
<option value="price">Price</option>
</select>
<br />
Enter Search Term <br />
<input name="searchterm" type="text" size="40"/> <br />
<input type="submit" name="submit" value="Search"/>
</form>
</body>
</html>
Code:
<html>
<head>
<title>B&B cars</title>
</head>
<body>
<h1>Boys and Babes cars</h1>
<?php
//Some short variable declared
$searchtype=$_POST['searchtype'];
$searchterm=trim($_POST['searchterm']);
if (!$searchtype || !$searchterm) {
echo 'You did not enter any search term.';
exit;
}
if (!get_magic_quotes_gpc()) {
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
}
@ $db = new mysqli('localhost', 'root', '', 'cars');
if (mysqli_connect_error()) {
echo 'Error: Was not able to connect.';
exit;
}
$query = "select * from cars where ".$searchtype." like '%".$searchterm."%'";
$result = $db->query($query);
$num_results = $result->num_rows;
echo "<p>Number of cars found: ".$num_results."</p>";
for ($i=0; $i < $num_results; $++) {
$row = $result->fetch_assoc();
echo "<p><strong>". ($i+1).". Car: ";
echo htmlspecialchars(stripslashes($row['car']));
echo "</strong><br />Make: ";
echo stripslahes($row['make']);
echo "<br />Year: ";
echo stripslashes($row['year']);
echo "<br />Price: ";
echo stripslashes($row['price')];
echo "<p />";
}
$result->free();
$db->close();
?>
</body>
</html>
When i run both code above, I get the error messages below.
Code:
Notice: Undefined index: searchtype in C:\xampp\htdocs\menre\products\cars\results.php on line 9
Notice: Undefined index: searchterm in C:\xampp\htdocs\menre\products\cars\results.php on line 10
You have not entered search details. Please go back and try again.
Code:
Notice: Trying to get property of non-object in C:\xampp\htdocs\menre\products\cars\results.php on line 33
Number of cars found:
Fatal error: Call to a member function free() on a non-object in C:\xampp\htdocs\menre\products\cars\results.php on line 49
I still do not know what I am doing wrong. I will really appreciate your help please.
Menre