Getting the result into a text box
I have two tables to which I can apply the changes. But I need to redo the changes made based on certain criteria. Now for the first table, any changes made are repeated, but I'm not sure how to revert the changes if they are made to the second table (else).
if (isset($_POST['submit']))
{
if (isset($_POST['ID'])) {
$sql = "SHOW COLUMNS FROM Employees";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)){
$tempname = $row['Field'];
// Changes Function
$sqlCheck = "SELECT * FROM Employees WHERE ID='".$_GET["id"]."' AND (".$row['Field']." NOT LIKE '".$_POST[$tempname]."')";
$result3 = mysqli_query($con,$sqlCheck);
if (mysqli_num_rows($result3) > 0) {
// output data of each row
while($row3 = mysqli_fetch_array($result3)) {
$sql3 = "INSERT INTO `Changes` (`Table`, `ID`, `Attribute`, `DateChanged`, `HRUser`, `OldValue`, `NewValue`) VALUES ('Employees', '".$_GET["id"]."', '".$row["Field"]."', '".date("d/m/Y h:i:sa")."', '$login_session', '$row3[$tempname]', '$_POST[$tempname]')";
if (mysqli_query($con,$sql3) === TRUE) {
} else {
echo "Error: " . $sql3 . "<br>" . mysqli_error($con);
}
}
}
//End Changes Function
$sql2 = "UPDATE Employees SET ".$row['Field']."= '$_POST[$tempname]' WHERE ID='".$_GET["id"]."'";
$result2 = mysqli_query($con,$sql2);
if (mysqli_query($con,$sql2) === TRUE) {
} else {
echo "Error: " . $sql2 . "<br>" . mysqli_error($con);
echo '<script>swal("Error", "Something went wrong '.mysqli_error($con).'", "error");</script>';
}
}
echo '<script>swal("Success", "Changes have been saved", "success");</script>';
}
//End If POST Submit True
else
{
$sql = "SHOW COLUMNS FROM Candidates";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)){
$tempname = $row['Field'];
// Changes Function
$sqlCheck = "SELECT * FROM Candidates WHERE ID='".$_GET["cid"]."' AND (".$row['Field']." NOT LIKE '%".$_POST[$tempname]."%')";
$result4 = mysqli_query($con,$sqlCheck);
if (mysqli_num_rows($result4) > 0) {
// output data of each row
while($row4 = mysqli_fetch_array($result4)) {
$sql4 = "INSERT INTO `Changes` (`Table`, `ID`, `Attribute`, `DateChanged`, `HRUser`, `OldValue`, `NewValue`) VALUES ('Candidates', '".$_GET["cid"]."', '".$row["Field"]."', '".date("d/m/Y h:i:sa")."', '$login_session', '$row4[$tempname]', '$_POST[$tempname]')";
if (mysqli_query($con,$sql4) === TRUE) {
} else {
echo "Error: " . $sql4 . "<br>" . mysqli_error($con);
}
}
}
+3
source to share