I am building an sql statement and I am using a foreach loop to create the statement. Everything looks good with the sql statement when I echo it; but the last update field has a comma , that is not needed. How to I account for the last $key => $value set in the array that match my criteria and not have a comma?
Newbie in search of knowledge
Code:
$sql = "UPDATE facform SET ";
foreach ($_POST as $key => $value) {
if($key != 'submit' && $value != ''){
$sql .= "$key = $value, ";
}
}
$sql .= "WHERE id = $id";
Newbie in search of knowledge