I am trying to take my Javascript variable and pass it to a PHP variable using AJAX so I can update my SQL. Currently the function is being called but AJAX is not sending the data to PHP.php.
CODE UPDATE:
function placeData(){
//Variable is caled and input is updated//
var hour1Data = document.getElementById("hourDataInput").value;
document.getElementById("hour1").innerHTML = hour1Data;
//Launch AJAX//
$.ajax({
type: "POST",
url: "PHP.php",
data: {hour1Data: "hello", loginName: <?php echo $_POST['loginName'] ?>},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(result){
alert(result.d);
console.log(result);
}
});
}
//php.php
if(isset($_POST['hour1Data']))
{
echo "something is working";
print_r($_POST); //Check the values here first
$hour1Data = $_POST['hour1Data'];
$sql = "UPDATE `$user` SET `$dateName`='$hour1Data' WHERE hour=1";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
}
else {
echo "problem adding value";
}
}