Guest User

Untitled

a guest
Mar 4th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. <?php
  2.  
  3. $json = trim(file_get_contents("php://input"));
  4.  
  5. function json_decode_nice($json, $assoc = FALSE){
  6. $json = str_replace(array("\n","\r"),"",$json);
  7. $json = preg_replace('/([{,]+)(\s*)([^"]+?)\s*:/','$1"$3":',$json);
  8. return json_decode($json,$assoc);
  9. }
  10.  
  11. $decoded = json_decode_nice($json);
  12.  
  13. $servername = "";
  14. $username = "";
  15. $password = "";
  16. $dbname = "";
  17.  
  18. $conn = mysqli_connect($servername, $username, $password, $dbname);
  19. if (!$conn) {
  20. die("Connection failed: " . mysqli_connect_error());
  21. }
  22.  
  23. $amount = $decoded->resource->amount->total;
  24. echo $amount;
  25.  
  26. $sql = "INSERT INTO payments (amount)
  27. VALUES (" . $amount . ")";
  28.  
  29. if (mysqli_query($conn, $sql)) {
  30. echo "New record created successfully";
  31. } else {
  32. echo "Error: " . $sql . "<br>" . mysqli_error($conn);
  33. }
  34.  
  35. mysqli_close($conn);
  36. exit();
  37. ?>
Add Comment
Please, Sign In to add comment