<?php
header('Access-Control-Allow-Origin: *');
session_start();

if (!$_SESSION["manu"]) {
    http_response_code(401);
    die();
}

$manu = $_SESSION["manu"];

include_once("db_connect.php");
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
} 

//var_dump(json_decode(file_get_contents("php://input")));
$postData = json_decode(file_get_contents("php://input"));

$photo = $postData->photo;
$nfc = $postData->id;


$query = '';
if ($photo === '1'){
    $query = "UPDATE items SET photo1 = '' WHERE manu = '" .$manu. "' AND nfc = '" .$nfc. "' ";    
}
if ($photo === '2'){
    $query = "UPDATE items SET photo2 = '' WHERE manu = '" .$manu. "' AND nfc = '" .$nfc. "' ";    
}
if ($photo === '3'){
    $query = "UPDATE items SET photo3 = '' WHERE manu = '" .$manu. "' AND nfc = '" .$nfc. "' ";    
}
if ($photo === '4'){
    $query = "UPDATE items SET photo4 = '' WHERE manu = '" .$manu. "' AND nfc = '" .$nfc. "' ";    
}

if ($mysqli->query($query) === true) {
    echo "Success: Record saved. [" .$query. "]";
    http_response_code(200);
} else {
    echo "Error: Process failed - " . $mysqli->error;
    http_response_code(500);
}

$mysqli->close();
//var_dump(json_decode(file_get_contents("php://input")));

?>