我一直在构建它,并且一切工作正常-但是,我连接的数据库无法更新-更新文本区域后,我的代码甚至告诉我它成功了,所以我真的不知道该做什么是错误的...下面的代码!
我已经检查了所有的合成税,数据库中的名称和代码中的字母-似乎没有什么问题。
检查页面没有错误。
<div class="container-fluid">
<textarea name="diary" id="diary" class="form-control"></textarea>
</div>
<?php include("footer.php");?>
<?php
session_start();
if(array_key_exists("content", $_POST)){
include ("connection.php");
$query = "UPDATE `users` SET `diary` = '".mysqli_real_escape_string($link, $_POST['content'])."' WHERE id = ".mysqli_real_escape_string($link,$_SESSION['id'])." LIMIT 1";
if(mysqli_query($link, $query)){
echo "success";
} else {
echo "failed";
}
}
?>
<?php
$link = mysqli_connect("*******", "********", "xxxxxxx", "*******");
if (mysqli_connect_error()){
die("Database connection error");
}
?>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script type="text/javascript">
$(".toggleForms").click(function(){
$("#signUpForm").toggle();
$("#loginForm").toggle();
});
$("#diary").on('input propertychange', function(){
$.ajax({
method: "POST",
url: "updatedatabase.php",
data: { content: $("#diary").val() }
})
.done(function( msg ) {
alert( "Data Saved: " + msg);
});
});
</script>