【发布时间】:2021-04-16 00:26:14
【问题描述】:
每当我单击提交按钮时,我的 ajax 都没有给我一个成功错误或失败错误。我的 MySQL 设置正确。我想更新我的数据库,因为出于某种原因,PHP 只是在一列中放了一个 3,所以我只想将它更新为实际的帐户类型(1、2、3、&4、&5)。我在提交按钮上有 2 个 ajax 函数,所以可能是这种情况,但我见过有超过 2 个 ajax 函数的网站,所以这不应该是问题。我认为这与 ajax 中的数据有关,但我不知道该放什么。
ajax:
$("#signUpButton").click(function(){
if($("#dproPlayerAccount").html() === "Pro Player Account") {
$.ajax({
type: "POST",
url: "proPlayAccountClicked.php",
dataType: "json"
}).done(function(proUpdate){
console.log(proUpdate);
}).fail(function(xhr, textStatus, errorThrown) {
console.log("Error Requesting. Please Try Again Later.");
}); }
else if($("#dfreePlayerAccount").text() === "Free Player Account") {
$.ajax({
type: "POST",
url: "freePlayAccountClicked.php",
dataType: "json"
}).done(function(freeUpdate){
console.log(freeUpdate);
}).fail(function(xhr, textStatus, errorThrown) {
console.log("Error Requesting. Please Try Again Later.");
});
}
else if($("#dpremiumPlayerAccount").text() === "Premium Player Account") {
$.ajax({
type: "POST",
url: "premiumPlayAccountClicked.php",
dataType: "json"
}).done(function(update){
console.log(update);
}).fail(function(xhr, textStatus, errorThrown) {
console.log("Error Requesting. Please Try Again Later.");
});
}
else if($("#dproCreatorAccount").text() === "Pro Creator Account") {
$.ajax({
type: "POST",
url: "proCreatorAccountClicked.php",
dataType: "json"
}).done(function(cproUpdate){
console.log(cproUpdate);
}).fail(function(xhr, textStatus, errorThrown) {
console.log("Error Requesting. Please Try Again Later.");
}); }
else if($("#dpremiumCreatorAccount").text() === "Premium Creator Account") {
$.ajax({
type: "POST",
url: "premiumCreatorAccountClicked.php",
dataType: "json"
}).done(function(cpremiumUpdate){
console.log(cpremiumUpdate);
}).fail(function(xhr, textStatus, errorThrown) {
console.log("Error Requesting. Please Try Again Later.");
});
}
})
我的 PHP 文件具有相同的内容,但只是计划的值不同。例如 plan="1"(2, 3, &4, &5)。
<?php
session_start();
$link = mysqli_connect("********", "********", "********", "********");
if(mysqli_connect_error()) {
die("Couldn't connect to the database. try again later.");
}
$query = "SELECT * FROM `users`";
if($result = mysqli_query($link, $query)) {
$row = mysqli_fetch_array($result);
}
//The plan value is different for the 5 different PHP files.
$query = "UPDATE KingOfQuiz SET plan='1' WHERE ".$row['id'];
echo json_encode($query);
?>
【问题讨论】:
-
首先分离你的代码 .. 用简单的
console.log('yes')尝试 if/else 语句,看看 if/else 是否正常工作.. 然后直接使用每个 ajax,看看你会得到什么..在您检查一切正常后将两者结合在一起并检查 -
好的,我去看看!
-
控制台不显示任何消息
-
WHERE子句中的UPDATE查询中存在错误。应该有类似" ... WHERE theColumn = " . $row['id']; -
我没有看到 MySQL 将
'3'放在任何地方。我什至没有看到INSERT... 另外,您应该使用准备好的语句,这样您的数据库就不会受到攻击。
标签: javascript php jquery mysql ajax