I want to Update my database with a variable from javascript.
This is my javascript code i want the testusersGeld variable to transfare over to php.
var testusersGeld = 111;
var sendUsersGeld = new XMLHttpRequest();
sendUsersGeld.open("POST", "usersGeldSenden.inc.php");
sendUsersGeld.setRequestHeader("Content-Type", "application/json");
sendUsersGeld.send(testusersGeld);
and this is my php code:
<?php
session_start();
$requestPayload = file_get_contents("php://input");
$object = json_decode($requestPayload);
var_dump($object);
if(isset($_POST['update']))
{
require_once 'includes\dbh.inc.php';
$query = "UPDATE users SET usersGeld='".$object."' WHERE usersName LIKE '{$_SESSION["usersName"]}'";
$result = mysqli_query($conn, $query );
if($result)
{
echo 'Data Updated';
}else{
echo 'Data Not Updated';
}
mysqli_close($conn);
}
When i var_dump than i can see the 111 but when i try to echo it out it wont work. The part of Update works when i use another variable.