I'm writing a code for MySQL search but it is not working
im using PHP class and this is the code:
data_model.php
<?php
$data = new Data();
if(isset($_GET['q'])) {
$data->$_GET['q']();
}
class Data {
function __construct(){
if(!isset($_SESSION['id'])){
header('location:../../');
}
}
function getSubject($search){
global $con;
$q = "select * from subject where code like '%$search%' or title like '%$search%' order by code asc";
$r = mysqli_query($con, $q);
return $r;
}]
subject.php
<?php
include "data/data_model.php";
$search = isset($_POST["search"]);
$subject = $data->getSubject($search);
?>
<form action="subject.php" method="post">
<label>
<input type="text" class="form-control" name="search" placeholder="Search Subject..." >
</label>
<button type="submit" name="search" class="btn btn-success" value="search"><i class="fa fa-search"></i> Search</button>
</form>
is there anything wrong in my code? I also use the getSubject in getting data from the db table to my html table and it has no problems but in searching it is not working?
Can anyone help me? Thanks in advance.