I want to protect publicly editable variables from SQL injection.
Here's an example of code showing collected form variables to be updated. First idea was to protect the variables as below;
$val1 = $val2 = strtoupper;
$val1 = $val2 = strip_tags;
$val1 = $val2 = trim;
$val1 = $val2 = mysqli_real_escape_string;
The next idea is to protect the database query as below;
$update_customer = "update customer set val_1='$val1',val_2='$val2' where foo='$foo'"; //update values set
$update_cust = strtoupper($update_customer);
$update_cust = strip_tags($update_customer);
$update_cust = trim($update_customer);
$update_cust = mysqli_real_escape_string($con, $update_customer);
$update_cust = mysqli_query($con, $update_customer); //inititate query
I presume using both ideas wouldn't be necessary but I'm not 100% on which I should use.