【发布时间】:2017-12-02 21:19:20
【问题描述】:
我正在尝试通过 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
但是该行没有插入到数据库中
【问题讨论】:
-
那么你得到的实际错误是什么?
-
在每个阶段调试您的脚本并找到实际问题..
-
列名不能用单引号括起来。 "INSERT INTO cmets ('comment') VALUES ('".$contentToSave."')"
-
@AndyHolmes 仅刷新页面即可
-
@JYoThI 让我试试
标签: php jquery mysql ajax mysqli