I have a function that concatenates a query from POST variables, I do this with a foreach:
$id = $_POST['empId'];
$query = "UPDATE userInfo SET ";
foreach ($_POST as $key => $value) {
$query .= "$key = '$value', ";
}
$query .= " WHERE id = '$id'";
How can I know when the last iteration is, in order to remove the final comma and thus be able to build the query correctly?