I'm not sure if I have done right when I use AJAX to send some info to a PHP-page with some code that connects to a database and stores a piece of text. A PHP-page that AJAX call, must that PHP-page be different compared to a common PHP-page? It's not working, I get a 404 Not Found message?
Here is the PHP-page:
<?php
session_start();
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
$replyArticleId = isset($_POST['replyArticleId']) ? $_POST['replyArticleId'] : '';
$replyText = isset($_POST['replyText']) ? $_POST['replyText'] : '';
$replySign = $_SESSION['accountId'];
date_default_timezone_set("Europe/Stockholm");
$date = new DateTime();
$replyDate = $date->format('Y-m-d H:i:s');
$tableUser = DB_PREFIX . WS_DB_USER;
$tablePost = DB_PREFIX . WS_DB_POST;
$tableComment = DB_PREFIX . WS_DB_COMMENT;
$tableArticle = DB_PREFIX . WS_DB_ARTICLE;
$tableReply = DB_PREFIX . WS_DB_REPLY;
// Add new comment
$query1 = "INSERT INTO {$tableReply} (replyArticleId, replyText,replyUserId,
replyDate) VALUES ('{$replyArticleId}','{$replyText}','{$replySign}', '{$replyDate}');";
$query2 = "UPDATE {$tableArticle} SET articleDateUpdated = NOW() WHERE articleId = {$replyArticleId};";
$res = $mysqli->query($query1) or die($mysqli->error);
$res = $mysqli->query($query2) or die($mysqli->error);
$mysqli->close();
This is the AJAX code that I use to call and send some test content:
$.ajax({
url: "PAddReplyProcessAJAX.php?replyArticleId=1",
type: "POST",
dataType: "text",
data: "replyText=" + "test"
});
?>