I'm working on Scrumpoker with Vue js.
I have a model for users,sessions and these stored in my database with properties like sessionID, nameID, userID, etc.
I'm trying to let an user join in a room which is not created by him.
If I try to, I get an error message looking at the web dev panel saying:
POST http://127.0.0.1:8090/xdd/src/api/user/create.php 400 (Bad Request)
vue-resource.esm.js?f3ef:1082
When I load my local path url including the create.php it says:
Notice: Trying to get property 'userName' of non-object in C:\laragon\www\xdd\src\api\user\create.php on line 19
Notice: Trying to get property 'sessionId' of non-object in C:\laragon\www\xdd\src\api\user\create.php on line 20
Anyone could help me ? It's the last thing to fix (with playing cards) the biggest issues speaking about api's.
Here is my code of the user/create.php:
<?php
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/db.php';
include_once '../models/user.php';
$database = new Database();
$db = $database->getConnection();
$user = new User($db);
$data = json_decode(file_get_contents("php://input"));
$user->userName = $data->userName;
$user->userSession = $data->sessionId;
if($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
echo "OPTIONS";
} else {
switch($user->create()){
case "NEW USER":
$insertId = $db->lastInsertId();
echo "$insertId";
break;
case "EXISTING USER":
echo "$user->userId";
break;
case "SESSION NOT FOUND":
http_response_code(404);
break;
default:
http_response_code(400);
}
}
?>
Request URL: http://127.0.0.1:8090/xdd/src/api/user/create.php
Request Method: POST
Status Code: 400 Bad Request
Remote Address: 127.0.0.1:8090
Referrer Policy: no-referrer-when-downgrade
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: POST
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Length: 95
Content-Type: application/json; charset=UTF-8
Date: Wed, 11 Sep 2019 13:53:47 GMT
Server: Apache/2.4.35 (Win32) OpenSSL/1.1.0i PHP/7.2.11
X-Powered-By: PHP/7.2.11
Provisional headers are shown
Accept: application/json, text/plain, */*
Content-Type: application/json;charset=UTF-8
Origin: http://localhost:8080
Referer: http://localhost:8080/join/32
Sec-Fetch-Mode: cors
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
{userName: "a", sessionId: "32"}
sessionId: "32"
userName: "a"