【问题标题】:Axios does not insert value into tableAxios 不向表中插入值
【发布时间】:2020-08-17 12:22:36
【问题描述】:

我不明白,我将axios 请求发送到insert.php,但由于某种原因它没有找到它。变量 note_text = null。我知道这是因为我不知道我要发送哪个变量 2 参数。

我以为有一个变量$ _POST['note_text]

我的 axios 调用:

let app = new Vue({
    el: '#app',
    data: {
        newNote: '',
        info: {

        }
    },
    mounted: function() {

    },
    methods: {
        addNewNote: function() {
            alert('work');
            axios.post('insert.php', {
                note_text: this.newNote
            })
            .then(response => (this.info = response));
        }
    }
});

我的 php 调用:

$connect = mysqli_connect('127.0.0.1', 'root', '', 'axios');
$sql = "INSERT INTO todo (name) VALUES ('" . $_POST['note_text'] ."')";
$query = mysqli_query($connect, $sql);

【问题讨论】:

    标签: javascript php vue.js axios backend


    【解决方案1】:

    尝试使用PHP的std对象结构来获取post的变量。

    $connect = mysqli_connect('127.0.0.1', 'root', '', 'axios');
    $_POST = json_decode(file_get_contents("php://input"),true);
    echo $_POST['note_text'];
    $sql = "INSERT INTO todo (name) VALUES ('" . $_POST['note_text'] ."')";
    $query = mysqli_query($connect, $sql);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-30
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      相关资源
      最近更新 更多