I have problem with my code.
In this code I am sending some data to another server.
fetch("https://example.com/test.php", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
"isim": lastPlayersTouched[0].name,
"sure": getTime(scores)
})
});
And here I have database connection:
<?php
try {
$db=new PDO("mysql:localhost;dbname=test1_evet;charset=utf8",'test1_evet','N#rK%*?PkTki');
//echo "ok";
}
catch (PDOException $e) {
echo $e->getMessage();
}
?>
And the final part here I am trying to add posted things to add my database:
<?php
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Credentials: true");
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token , Authorization');
require_once 'baglan.php';
// if (isset($_POST)) {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$arr = json_decode(file_get_contents('php://input'), true);
$kaydet=$db->prepare("INSERT into test SET
isim=:isim,
sure=:sure
");
$insert=$kaydet->execute(array(
// 'isim' => $_POST['isim'],
'isim' => $arr['isim'],
// 'sure' => $_POST['sure']
'sure' => $arr['sure']
));
}
// }
?>
But the problem is, I can send data from another server to my current server with 200 OK code. But PHP doesn't add things I've sent to database. I mean not inserting to database. Can someone help me on that? I will be very happy if you guys help me.
Any fix?