I have a problem with my PHP script I have a search bar but when I redirect it to the class instead of running the script it shows me the PHP script. I am new to the OOP PHP programming style.
I am trying to achieve a really simple OOP search query on my database. But I am confused as to why it re-directs me to classes/class.House.inc rather than executing the script. Where am I going wrong?
I’ve tried looking online for a OOP tutorial online but had little luck 🙁 Any help would be welcomed!
index.php
<form method="post" action="classes/class.House.inc" name="search" id="searchform">
<input type="text" name="term" id="searchinput"/>
<input type="submit" name="submit" id="searchsubmit" value=""/>
</form>
classes/class.House.inc
<?php
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);
header ("Location: ../search.php");
}
return $this->data;
}}}
?>
search.php
<table width="500" border="1" cellpadding="5">
<tr>
<th width="16" scope="row">id</th>
<td width="95">bedrooms</td>
<td width="140">description</td>
<td width="104">roadname</td>
<td width="71">postcode</td>
</tr>
<?php
$obj = new House();
$obj->search();
foreach($obj->data as $val){
extract($val);
?>
<tr>
<td scope="row"><?php echo $id; ?></td>
<td><?php echo $bedrooms; ?></td>
<td><?php echo $description; ?></td>
<td><?php echo $roadname; ?></td>
<td><?php echo $postcode; ?></td>
</tr>
<?php
}
?>
</table>
at the index.php fix the form
and at search.php add this line
and why the script display that because apache configuration you need to put inc file as script excusable