I developing a small crud application with php and restful api. I want to sent the code 200 if a record is created and code 403 for error msgs. Below is my code:
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$age = $_POST['age'];
$query = $restObj->create_record($firstname,$lastname,$age);
echo json_encode([
"message" => $query ? "User Created" : "Error creating user"
]);
This is my function for creating record:
public function create_record($firstname,$lastname,$age)
{
$sql = "INSERT INTO table1 (firstname,lastname,age) VALUES ('$firstname','$lastname','$age')";
$query = mysqli_query($this->conn,$sql);
return $query;
}
The code works fine and I can create record but I don't know how to display code 200 and code 403 messages. Please Help