通过查询字符串插入mysql数据库

wmtdaxz3  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(218)

这个问题在这里已经有答案了

mysqli_fetch_assoc()需要参数/调用成员函数bind_param()时出错。如何获得实际的mysql错误并修复它(1个答案)
如何转义用作列名的保留字?mysql/create table(3个答案)
两年前关门了。
我正在尝试将数据保存到我的远程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);

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题