Using $this when not in object context in PHP

You are not inside instance of class to use $this. Try this, it will work

require_once 'models/Request.php';

$req = new Request;

if(isset($_POST['submit'])){
    $data = [
        'reqBy' => $_POST['reqBy'],
        'off' => $_POST['off'],
        'prob' => $_POST['prob']
    ];

    echo "<pre>";
      print_r($data);
    echo "</pre>";

    if($req->addRequest($data)){ //This is the line where it points the error
        echo 'Sucess';
    }else{
        echo 'Something';
    }
}
?>

Leave a Comment