Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
Update Database with javascript variable/ transfare javascript variable to php

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!