[英]Send data from Javascript to PHP using AJAX for updating the existing Mysql database
我正在研究我的蛇游戲項目的后端。我一直在嘗試通過將新的高分發送到 update.php 網頁來更新 mysql 數據庫的最大條目。
為了測試我的數據是否發送到update.php,我也發送了test=all good to update.php。但是當我回顯時,它沒有顯示在Z2567A5EC9705EB7AC2C984033E06瀏覽器中成功顯示沒有這樣的數據發送。
請告訴我為什么會這樣?
這是我的 xml http 請求的代碼部分。
'''
highscore=score;
document.querySelector("#my-high-score").textContent=highscore;
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "update.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-
urlencoded");
xhttp.send(`highest_score=${highscore}&test="all good"`);
'''
這是 update.php 文件
'''
<?php
session_start();
$link=mysqli_connect("shareddb-x.hosting.stackcp.net","gameusers-
31353746432","havd5n897","gameusers-
3135374592");
if(mysqli_connect_error())
die ("connection is not successfull");
echo "welcome user";
$x=90;
echo $x;
echo $_POST['test'];
if($_POST['highest_score'])
{
$high_score=$_POST['highest_score'];
$email=$_SESSION['email'];
if($_SESSION['highscore']<$high_score)
{
$query="UPDATE gameusers SET Max=$high_score WHERE Email= $email LIMIT
1";
echo $high_score;
mysqli_query($link,$query);
echo "all fit";
}
}
?>
'''
請有人告訴我我實際上在哪里犯了錯誤。
嘗試刪除“都很好”中的雙引號
xhttp.send(`highest_score=${highscore}&test="all good"`);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.