I want to update a MySQLi table achievements through PHP. The app is coded in AngularJS and measures various statistics. When a goal is met, I send the information to a PHP script using AngularJS's $http.post. PHP should then handle the information and update my table accordingly. The $http.post returns a success message, but the table is not updated. I am confident the database connection info is correct.
My AngularJS $scope.updatePhp function using $http.post:
$scope.updatePhp = function(table, column, value, whereColumn, whereValue) {
$http.post(
"update-data.php", {
'table': table,
'column': column,
'value': value,
'whereColumn': whereColumn,
'whereValue': whereValue
}
);
}
My AngularJS $scope.updatePhp function without using the .post shortcut:
$scope.updatePhp = function(table, column, value, whereColumn, whereValue) {
console.log("Updating. Table: " + table + ", column: " + column + ", value: " + value + ", where: " + whereColumn + ", whereValue: " + whereValue);
$http({
method: 'POST',
url: 'update-data.php',
data: { table: table.toString(), column: column.toString(), value: value.toString(), whereColumn: whereColumn.toString(), whereValue: whereValue.toString() },
headers: { 'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8' }
}).then(function successCallback(response) {
console.log("Success.");
}, function errorCallback(response) {
console.log("Error.");
});
}
My entire PHP file 'update-data.php`:
<?php
//CORS header stuff
header("Access-Control-Allow-Origin: *");
//PHP posted info
$info = file_get_contents('php://input');
//Update the table
$hostname_DB = "databaseHost";
$database_DB = "databaseName";
$username_DB = "databaseUser";
$password_DB = "databasePass";
$portnum_DB = "databasePort";
$mysqli = mysqli_connect($hostname_DB, $username_DB, $password_DB, $database_DB, $portnum_DB ) or die(mysqli_error());
$table = $info->table;
$column = $info->column;
$value = $info->value;
$whereColumn = $info->whereColumn;
$whereValue = $info->whereValue;
$query = "UPDATE '$table' SET '$column' = '$value' WHERE '$whereColumn' = '$whereValue' ";
$mysqli->query($query) or die(mysqli_error());
?>
I am using the PHP error_log and I am getting this error for each variable table, column, value, etc.:
PHP Notice: Trying to get property 'table' of non-object in /update-data.php on line 16.
There is definitely something wrong with the way the info is being posted or with how the posted info is being retrieved, not with the SQL.
Thank you in advance for any help you may be able to provide in sorting out this situation!