My ajax is not giving me a success error or a fail error whenever I click my submit button. My MySQL is properly set up. I want to update my database because for some reason the PHP just puts a 3 in one column, so I just want to update it to the actual account type(1, 2, 3, &4, &5). I have 2 ajax functions on the submit button, so maybe that might be the case but I've seen websites with more than 2 ajax functions, so that shouldn't be the issue. I think it has to do with the data in ajax but I don't know what to put there.
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.");
});
}
})
My PHP files have the same thing but just the plan is a different value. For example 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);
?>
question from:
https://stackoverflow.com/questions/65660464/update-mysql-database-table-using-ajax 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…