Below is my AJAX for updating rows in DB:
<script type='text/javascript'>
$("#editstatus_form").submit(function(e) {
$.ajax({
type: "POST",
url: "../../scripts/universal/update-status.php",
data: $("#editstatus_form").serialize(), // serializes the form's elements.
success: function(data) {
$("#update_status").html(data);
$("#updated_post").slideDown();
setTimeout(function() {
$('#updated_post').slideUp();
}, 3000);
}
});
e.preventDefault();
});
</script>
Now this code below is update-status.php
$sqlid = mysqli_real_escape_string($conn, $_POST['sqlid']);
$updated_status = mysqli_real_escape_string($conn, $_POST['updated_status']);
$date_edited = mysqli_real_escape_string($conn, $_POST['date_edited']);
$updateSQL = sprintf("UPDATE forum SET content_posting='$updated_status', date_edited='$date_edited' WHERE sqlid= '$sqlid'");
$input = $_POST['updated_status'];
preg_match_all("/#(\S{1,})/", $input, $matches);
foreach($matches[1] as $match){
if (!file_exists('../../hashtag/' . $match)) {
mkdir('../../hashtag/' . $match, 0755, true);
copy("hashtagcontainer.php", "../../hashtag/$match/index.php");
}
}
$Result1 = mysqli_query($conn, $updateSQL) or die(mysql_error());
if (!function_exists('convertAll')) {
function convertAll($str) {
$regex = "/[@#]([\w\.\-]+)/";
$hrefs = ['#' => '../../hashtag/', '@' => '../../users/'];
$result = preg_replace_callback($regex, function($matches) use ($hrefs) {
return sprintf('<a href="%s%s/" style="color:#039BE5;text-decoration:none;">%s</a>', $hrefs[$matches[0][0]], strtolower($matches[1]), $matches[0]);
}, $str);
return($result);
}
}
$status = convertAll($_POST['updated_status']);
echo nl2br($status);
?>
This all works (it updates the posts and everything) until a user tries to tag someone using the @.
If someone includes that in their post it will update in the DB and give me a 200 Response but this $("#update_status").html(data);
does not work. Rather it empties #update_status.
Can anyone help me out here?