I have a script in PHP that performs a multyquery update after taking some values in different inputs form. Everything works fine if I fill all these forms and press save. However if I leave one field open I receive an error as that value can't be empty.
Now, what I'd like to do is that when the php/html form has an empty input field the record shouldn't be changed and keep the value is currently in the database.
Here's part of my current code
$sql = "UPDATE task SET name='$aName', surname='$aSurname', htbTotal='$ahtbtotal' WHERE id=1;";
$sql .= "UPDATE task SET name='$fName', surname='$fSurname', htbTotal='$fhtbtotal' WHERE id=2;";
if ($conn->multi_query($sql) === TRUE) {
echo "Record updated successfully";
$risposta= "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
$risposta= "Error updating record: " . $conn->error;
}
This is an input example
<input id="aName" name="aName" type="text" placeholder="">
Any suggestion?
Thanks in advance!
Update: Just to make more clear, I don't need a validation. I want the user to leave some input empty if they don't want to fill but this shouldn't rewrite the related row value inside the database