Guest User

Untitled

a guest
Jan 15th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. $scope.updatePhp = function(table, column, value, whereColumn, whereValue) {
  2. $http.post(
  3. "update-data.php", {
  4. 'table': table,
  5. 'column': column,
  6. 'value': value,
  7. 'whereColumn': whereColumn,
  8. 'whereValue': whereValue
  9. }
  10. );
  11. }
  12.  
  13. $scope.updatePhp = function(table, column, value, whereColumn, whereValue) {
  14.  
  15. console.log("Updating. Table: " + table + ", column: " + column + ", value: " + value + ", where: " + whereColumn + ", whereValue: " + whereValue);
  16.  
  17. $http({
  18. method: 'POST',
  19. url: 'update-data.php',
  20. data: $.param({ table: table.toString(), column: column.toString(), value: value.toString(), whereColumn: whereColumn.toString(), whereValue: whereValue.toString() }),
  21. headers: { 'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8' }
  22. }).then(function successCallback(response) {
  23. console.log("Success.");
  24. }, function errorCallback(response) {
  25. console.log("Error.");
  26. });
  27.  
  28. }
  29.  
  30. <?php
  31.  
  32. //PHP posted info
  33. $info = json_decode(file_get_contents('php://input'), true);
  34.  
  35. //Update the table
  36. $hostname_DB = "databaseHost";
  37. $database_DB = "databaseName";
  38. $username_DB = "databaseUser";
  39. $password_DB = "databasePass";
  40. $mysqli = mysqli_connect($hostname_DB, $username_DB, $password_DB, $database_DB, "port#" ) or die(mysqli_error());
  41.  
  42. $table = $info->table;
  43. $column = $info->column;
  44. $value = $info->value;
  45. $whereColumn = $info->whereColumn;
  46. $whereValue = $info->whereValue;
  47.  
  48. $query = "UPDATE '$table' SET '$column' = '$value' WHERE '$whereColumn' = '$whereValue' ";
  49. $mysqli->query($query) or die(mysqli_error());
  50.  
  51. ?>
Add Comment
Please, Sign In to add comment