foreach ($_POST['userGroup'] as $val) {
// Check if user's added already
$sql = "SELECT userID FROM involved WHERE incidentID = $iid AND userID = $val";
$checkSQL = mysql_query($sql) or die(mysql_error);
$checkRows = mysql_num_rows($checkSQL); // if == 1, user is added
if($checkRows == 0) {
// Add user
$sql = "INSERT INTO involved ( incidentID, userID ) VALUES ( $iid, $val )";
$insertUser = mysql_query($sql);
}
}
// Check if user is added but should not be
$sql = "SELECT userID, involvedID FROM involved WHERE incidentID = $iid";
$involvedSQL = mysql_query($sql) or die(mysql_error);
while($row = mysql_fetch_assoc($involvedSQL)) {
$involvedID = $row['involvedID'];
echo "<br><br>Setting involvedID " . $involvedID . "<br>";
$userID = $row['userID'];
echo "Setting userID " . $userID . "<br>";
if (!in_array($userID, $_POST['userGroup'])) {
// Remove user
echo "Could not find user " . $userID . " on involvedID " . $involvedID . "<br>";
$delsql = "DELETE FROM involved WHERE involvedID = $involvedID";
echo "<br>" . $delsql;
$deleteSQL = mysql_query($delsql) or die(mysql_error);
}
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE