具有多个属性的jQuery$.get()

jQuery $.get() with multiple attributes

本文关键字:get jQuery 属性      更新时间:2023-09-26

我已经编写了以下代码,但不明白为什么它不起作用。在我的php-error.log中没有错误。

我正在尝试用ajax get更改a中的一行。我的变量都已定义,并且Mysql连接正常工作。那么我做错了什么?

Javascript:

$.get("rename_task.php", {content: userinput, id: this_task});

PHP:

<?php
$db_connect = mysqli_connect('localhost', 'helreak', 'Password', 'helreak_todo');
$task_content = $_GET['content']; 
$task_id = $_GET['id'];
if (mysqli_connect_errno()){
    echo "Failed to connect to MySQL:"  . mysqli_connect_error();
}
mysqli_query($db_connect,"UPDATE list_1 SET Content=$task_content WHERE State=1 AND ID=$task_id");
mysqli_close($db_connect);
?>

谢谢,Luca

尝试

 <?php
    $db_connect = mysqli_connect('localhost', 'helreak', 'Password', 'helreak_todo');
        $task_content = $_GET['content']; 
        $task_id = $_GET['id'];
        if (mysqli_connect_errno())
            {
                echo "Failed to connect to MySQL:"  . mysqli_connect_error();
            }
        $query = ($db_connect,"UPDATE list_1 SET Content='$task_content' WHERE State=1 AND ID='$task_id' ");

    mysqli_close($db_connect);?> 

没有错误,因为您没有使用应该使用的or die mysqli_error()

其次,假设Content是一个字符串,它应该用引号Content='$task_content'括起来。如果您添加了or die..

,则查询(不带引号)将引发错误