我正在尝试将数据保存到远程MySQL数据库。我在Postman上测试了此脚本。但这给了这个错误{"error":true,"message":"Please try later"}
我尝试了不同的方法插入。但是我主要是接受500个内部服务器错误。我该如何解决?
<?php
define('DB_HOST','**.**.***.***');
define('DB_USERNAME','*******');
define('DB_PASSWORD','*******');
define('DB_NAME', '*******');
//Connecting to the database
$conn = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
if($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$response = array();
if($_SERVER['REQUEST_METHOD']=='POST'){
$emoji = $_POST['emoji'];
$comment = $_POST['comment'];
$date = $_POST['date'];
$stmt = $conn->prepare("INSERT INTO datas (emoji, comment, date) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $emoji, $comment, $date);
if($stmt->execute()){
//making success response
$response['error'] = false;
$response['message'] = 'Name saved successfully';
}else{
//if not making failure response
$response['error'] = true;
$response['message'] = 'Please try later';
}
}else{
$response['error'] = true;
$response['message'] = "Invalid request";
}
echo json_encode($response);