I'm inserting addedworkhours into my database, but the problem is that if i insert several times for the same id (afnumber), the old and new values are kept. The new val doesn't replace the old one. I'm trying to update it (the commented section) however not at all successful. Always the same result. I'm trying to get it to work using an if/else condition, to check whether a value in a column is empty, then insert. If not update, any help in the if condition statement?
The way I'm getting the updates output:
if(isset($_POST['submit'])){
if(AddedWH IS NULL) THEN
$addedhours = $_POST['AddedHours'];
$selectaf = $_POST['SelectAF'];
$sql1="INSERT INTO `editedworkhours` (`AFNumber`,`AddedWH`) VALUES('$selectaf','$addedhours')";
$getResult =mysql_query($sql1);
if(mysql_affected_rows() > 0)
{
}
else{
}
else
$tempname = $row['Field'];
$sql2 = "UPDATE editedworkhours SET AddedWH ='".$_GET["addedhours"]."' WHERE AFNumber='".$_GET["selectaf"]."'";
$result2 = mysqli_query($con,$sql2);
if ($con->query($sql2) === TRUE) {
} else {
echo "Error: " . $sql2 . "<br>" . $con->error;
echo '<script>swal("Error", "Something went wrong '.$con->error.'", "error");</script>';
}
echo '<script>swal("Success", "Changes have been saved", "success");</script>';
} END IF;
echo $menu;