如何将数组发布到数据库中?

我将来自用户表单的输入存储到数组中,并且想将此数组添加到数据库中,我没有使用普通的表单POST方法,因为在同一表单div中没有​​添加按钮,因此我使用一个函数而不是addRecord()并且我的数组是names []

这是我的index.php页面

names = [];

function addRecord() {
    var request = new XMLHttpRequest();
    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    request.open("POST", 'inputs.php', true);
    request.send(names);
}

这是我的php.php页面

    $User = $_SESSION['name'];

}if (!empty($names )) {     
    $sql = "INSERT INTO users (names)
        VALUES ('names')";
        if (!mysqli_query($con,$sql)){
        $message = "there was an error the input was not inserted";
        echo "<script type='text/javascript'>alert('$message');</script>";
} 
评论