I would do it in this way.
$sql="UPDATE `" . $table_name . "` SET `is_delete` = 1 WHERE `" . $field_id . "` = '$record_id'";
Question
I am trying to create a dynamic page to soft-delete record from various tables.
Can anyone help me to fix the following statement? I am so confused to the quotes when it comes to variables:
$table_name = $_REQUEST['t'];
$record_id = $_POST['rid'];
$field_id = print_var_name($rid);
$sql="UPDATE `$table_name` SET `is_delete` = 1 WHERE `$field_id` = '$record_id'";
Solution
I would do it in this way.
$sql="UPDATE `" . $table_name . "` SET `is_delete` = 1 WHERE `" . $field_id . "` = '$record_id'";
OTHER TIPS
try this.
$table_name = $_REQUEST['t'];
$record_id = $_POST['rid'];
$field_id = print_var_name($rid);
$sql="UPDATE ".$table_name." SET ". is_delete." = 1 WHERE " .$field_id. " =" .$record_id;
Or change your query like this.
$sql="DELETE FROM ".$table_name." WHERE ".$field_id. "=".$record_id;