Hi I am trying to create a search function using OOP PHP however when I run my query and enter false data I am still getting results. Results that are not in the database.
I feel like I am lacking something in my code,
Perhaps my query is wrong I'm not sure as I am new to the whole programming aspect.
Any help would be welcomed!
index.php
<?php
include("classes/class.House.inc");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>UndergradPad</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="bodyWrapper">
<div id"header">
<img id="banner" alt="UnderGradPad Logo" src="images/banner.png"/>
</div> <!-- End header -->
<div id="search">
<h1>Find student accomodation</h1><br/>
<p> Location </p>
<form method="post" action="search.php" name="search" id="searchform">
<input type="text" name="term" id="searchinput"/>
<input type="submit" name="submit" id="searchsubmit" value=""/>
</form>
<div class="help">e.g. 'PO5' or 'Portsmouth'</div>
</div> <!--End search -->
</body>
</html>
classes/class.House.inc
<?php
include("connect/class.Database.inc");
class House extends Database {
public function search (){
$query = "SELECT * FROM houses WHERE postcode like '%$term%'";
$result = $this->mysqli->query($query);
$num_result = $result->num_rows;
if($num_result > 0){
while($rows =$result->fetch_assoc()){
$this->data[]=$rows;
//print_r($rows);
}
return $this->data;
}
} else {
echo 'No Records Found';
}
} }
?>