With this code, I am getting only local correct value with variable $date
in MySQL column, because PHP gives me time so it must be correct. What should I change to save JSON post to PHP variables and correctly send it to SQL columns?
It's my JSON call:
{
"buyer":{
"id":142694,
"email":"test@example.com",
"quantity":1,
"sent_count":0,
"created_at":"2018-12-29T20:29:23+01:00"
},
"listing":{
"id":36,
"name":"GTA V STEAM KEY"
},
"database":{
"id":16141,
"available_codes_count":7
},
"payment":{
"id":null,
"code":null,
"amount":null,
"currency":null,
"done":false
},
"created_at":"2018-12-29T20:29:23+01:00"
}
<?php
$json = json_decode($_POST);
$email = var_dump($json->buyer->email);
$name = var_dump($json->listing->name);
$count = var_dump($json->buyer->quantity);
$code = var_dump($json->payment->code);
date_default_timezone_set('Europe/Warsaw');
$date = date("Y-m-d H:i:s", time());
$servername = "localhost";
$username = "test1";
$password = "test2";
$dbname = "test3";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO list (email, name, date, count, code)
VALUES ('".$email."', '".$name."', '".$date."', '".$count."', '".$code."')";
if ($conn->query($sql) === true) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();