I want to update a table where the table name is a variable. I can update the table just fine but when I try and make it a variable I get problems. I probably just don't know the syntax very well.
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$table = "settings";
$tr_title = $_POST['tr_title'];
$tr_slogan = $_POST['tr_slogan'];
$tr_signin = $_POST['tr_signin'];
$tr_makeacall = $_POST['tr_makeacall'];
$statment = $connect->prepare(
'UPDATE $table SET
tr_title = :tr_title,
tr_slogan = :tr_slogan,
tr_signin = :tr_signin,
tr_makeacall = :tr_makeacall
');
$statment->execute(array(
':tr_title' => $tr_title,
':tr_slogan' => $tr_slogan,
':tr_signin' => $tr_signin,
':tr_makeacall' => $tr_makeacall
));
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
I also tried doing an escape_string
$table = "settings";
$table = $mysqli->real_escape_string($table);
I'm pretty sure my syntax is just off.