gpt4 book ai didi

PHP、AJAX、MYSQLI、不插入行

转载 作者:行者123 更新时间:2023-11-29 18:43:04 25 4
gpt4 key购买 nike

我试图通过ajax请求将一行插入到数据库,但该行没有插入到数据库

 //Simple form
<div class="form_style">
<form action="#" method="POST">
<textarea name="content_txt" id="contentText" cols="45" rows="5"
placeholder="Enter some text"></textarea>
<button id="FormSubmit">Add record</button>
</form>
</div>

和response.php

if(isset($_POST["content_txt"])){
//MYSQL CLASS
include('includes/mysql.inc.php');
file_get_contents('php://input');
//Accessing the POST variables
$contentToSave = $_POST["content_txt"];
//Inserting the row
$insert_row = "INSERT INTO comments (comment) VALUES
('".$contentToSave."')";
$r = mysqli_query($dbc, $insert_row);
}
else
{
//This block is executing right the moment, seems like $_POST datas not
POSTING
header('HTTP/1.1 500 Error occurred, Could not process request!');
exit();
} //seems like maybe the jquery include file is not proper? but i checked it connecting not locally to the jquery library

但是该行没有插入数据库

最佳答案

在插入语句中,删除注释周围的单引号。如果你试图访问 MySQL 保留关键字,你需要的是反引号来正确转义

关于PHP、AJAX、MYSQLI、不插入行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44820618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com