I have a problem. I'm setting up a dynamic update, but I'm not able to mount the query on the parameters to update in the query. Follow the code below to be clear what I need:
function UpdateCommand($table, $params, $id){
$database = new Database();
$database->database_connect();
$select = "SELECT * FROM {$table}";
$resultselect = mysqli_query($database->database_connect(), $select);
// Aqui não consigo dar sequência
$query = "UPDATE {$table} SET {$params} WHERE id_{$table} = $id";
echo $query;
//$result = mysqli_query($database->database_connect(), $query);
$database->database_close_connection();
}
This update would serve for any table, which would be informed in the parameter. The same would happen with the id. The problem was in the part of the fields to be updated. And two things made it difficult for me.
1st - Each table can have a number of different columns, so I thought of putting a select to pick up those columns and then using them with the variables reported by the form, but I could not do that.
2nd - Even if I extracted the columns correctly from the table, how would I give%% of them to each column? That got a bit confusing for me.
I forgot to put that I would need to do a check of the $ _POST variables that were set. But this item here is less relevant, what matters most is the update.