I'm having an issue and i can't seem to see where the error is in my code. I'm trying to update a variable total
in my database using a ajax post function on my webpage. The function works as the alert is generated with the correct values when i click the button but my database is not updated. Here is the javascript function:
function buyeqc(){
var total = $('#eqctotal').val();
$.ajax({
url:"buyeqc.php", //the page containing php script
data: 'total='+total,
type: "POST", //request type
success:function(result){
if (total < "1") {
alert("Please enter a value greater than 0");
} else if (total > "1") {
alert("Thank you for your purchase of "+total+" EQC. Please refresh the page to view your updated balance.");
}
}
});
}
And here is the PHP script that it's posting to:
<?php
if (isset($_GET['total'])) {
session_start();
include_once 'dbh.inc.php';
$user = $_SESSION['u_uid'];
$eqcbal = $_SESSION['EQCBal'];
$total = $_GET['total'];
$sql = "UPDATE users SET EQCBal = '$total' WHERE user_uid = '$user';";
mysqli_query($conn, $sql);
}
?>
If you can point me in the right direction as to where my error is I would be greatful. I have a feeling it's something very simple or small! Thanks.