0

I'm having this error

Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\hrm\app\myAPI\attendance\punchIn.php on line 22

phnchIn.php

<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

include_once '../../config/Database.php';
include_once '../../models/Attendance.php';

$database = new Database();
$db = $database->connect();

$attendance = new Attendance($db);

// get posted data
// $data = json_decode(file_get_contents("php://input"));
$data = (object) $_POST;

// set attendance property values
$attendance::employee = $data->employee;
$attendance::in_time = $data->in_time;
$attendance::note = $data->note;

// create the attendance
if($attendance->punchIn()){
    echo '{';
        echo '"message": "Attendance was created."';
    echo '}';
}

// if unable to create the attendance, tell the user
else{
    echo '{';
        echo '"message": "Unable to create attendance."';
    echo '}';
}
?>

Any help would be a great help

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55

1 Answers1

0

You are using class properties with the syntax of static methods, which is causing the error. So...

// set attendance property values
$attendance::employee = $data->employee;
$attendance::in_time = $data->in_time;
$attendance::note = $data->note;

should be..

// set attendance property values
$attendance->employee = $data->employee;
$attendance->in_time = $data->in_time;
$attendance->note = $data->note;

If you're not familiar with static methods, they are methods which can be used without instantiating the class. In your example, it would be Attendance::some_static_method(); Here is more information from the PHP docs.

But properties are accessed by this syntax: $attendance->some_property;, which is what you want as far as I can tell. See the PHP docs for more information on properties.

dafoxuk
  • 439
  • 3
  • 8