我想通過Ajax請求插入一行到數據庫,但該行不插入到數據庫PHP,AJAX,mysqli的,不插入一行
//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評論(‘評論’)VALUES (「」。$ contentToSave。「」)」 – JYoThI