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

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

$mysqli = new mysqli("localhost", "afxtech1_myori", "myori2017", "afxtech1_myori");
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
} 

//{"jenama":"jenama1","model":"model1","produk":"idproduk1","sku":"sku1","remark":"remark1","type":"TOYS","attrib4":"BAT","attrib5":"1v","attrib6":"1kg","attrib7":"1saiz","prod_year":"2017","waranti":"tiada1","insuran":"tiada1","base1":"data:image/png;base64","base2":""}
//LPAD(COUNT(*)+1,3,'0'), 
$query = "INSERT items VALUES (
            LPAD((SELECT COUNT(*)+1 FROM items a),3,'0'),
            LPAD((SELECT COUNT(*)+1 FROM items a),3,'0'),
            '" .$postData->base1. "', 
            0, 
            '', 
            '" .$postData->jenama. "', 
            '" .$postData->model. "', 
            '" .$postData->attrib3. "', 
            '" .$postData->attrib4. "', 
            '" .$postData->attrib5. "', 
            '" .$postData->attrib6. "', 
            '" .$postData->attrib7. "', 
            '" .$postData->produk. "', 
            '" .$postData->sku. "', 
            '" .$postData->remark. "', 
            '" .$postData->type. "', 
            '" .$postData->waranti. "', 
            '" .$postData->insuran. "', 
            " .$postData->prod_year. ", 
            '" .$postData->manu. "'
            ) ";

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

$mysqli->close();


//var_dump(json_decode(file_get_contents("php://input")));

?>