Notice: Trying to get property 'id' of non-object in C:
<b>Notice</b>: Trying to get property 'id' of non-object in <b>C:
When i tried to update or delete it give this notice
<b>Notice</b>: Trying to get property 'id' of non-object in <b>C:UsersHusam Al-MasriPhpstormProjectsTODOapitasksupdate.php</b> on line <b>24</b><br /><br />
<b>Notice</b>: Trying to get property 'taskName' of non-object in
<b>C:UsersHusam Al-MasriPhpstormProjectsTODOapitasksupdate.php</b> on line <b>25</b><br /> <br />
<b>Notice</b>: Trying to get property 'taskDescription' of non-object in <b>C:UsersHusam Al-MasriPhpstormProjectsTODOapitasksupdate.php</b> on line <b>26</b><br />
{"message": "task was updated."}
in get and create the code worked, whats the wrong in my update code?
I search in stackoverflow with the same title but i see every body has a case different of my case so please no body say the question is duplicated.
And after the notice it echo {"message": "Task was deleted."}
<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: PUT");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
// get database connection
include_once '../../config/Database.php';
// instantiate models object
include_once '../../models/Tasks.php';
$database = new Database();
$db = $database->getConnection();
$tasks = new Tasks($db);
// get tasks data
$data = json_decode(file_get_contents("php://input"));
// set tasks property values
$tasks->id = $data->id;
$tasks->taskName = $data->taskName;
$tasks->taskDescription = $data->taskDescription;
// create the task
if($tasks->update()){
echo '{';
echo '"message": "task was updated."';
echo '}';
}
// if unable to update the task.
else{
echo '{';
echo '"message": "Unable to update task."';
echo '}';
}
?>
And this is function for update
function update(){
// query to insert record
$query = "UPDATE
" . $this->table_name . "
SET
taskName=:taskName,
taskDescription=:taskDescription
where
id=:id";
// prepare query
$stmt = $this->conn->prepare($query);
// sanitize
$this->taskName=htmlspecialchars(strip_tags($this->taskName));
$this->taskDescription=htmlspecialchars(strip_tags($this->taskDescription));
$this->id=htmlspecialchars(strip_tags($this->id));
// bind values
$stmt->bindParam(":taskName", $this->taskName);
$stmt->bindParam(":taskDescription", $this->taskDescription);
$stmt->bindParam(":id", $this->id);
// execute query
if($stmt->execute()){
return true;
}
return false;
}
Edit
And in postman it give me Unexpected '<'
Possible duplicate of Reference - What does this error mean in PHP?
– AymDev
Jun 30 at 14:52
why? please explain
– Husam Al-Masri
Jun 30 at 14:53
Who say this question duplicate ... please give me the link to see if there is question same my question
– Husam Al-Masri
Jun 30 at 16:15
What line is causing the error?
– Mr Glass
Jun 30 at 16:41
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
The problem, as always, is that the JSON doesn't look how you think it does.
– Ignacio Vazquez-Abrams
Jun 30 at 14:51