php - I have a form that updates some values in mysql, how do I avoid to update the cell when an input is empty?

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
Answer
Solution:
$sql = "UPDATE task SET";
if(strlen($_POST['aName'])>0)
{
$sql .= " name='$aName',";
}
if(strlen($_POST['aSurname'])>0)
{
$sql.=" surname='$aSurname',";
}
if(strlen($_POST['htbTotal'])>0)
{
$sql.=" htbTotal='$htbTotal'";
}
$sql.=" WHERE id=1;";
this way you can solve by comparison
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: composer detected issues in your platform: your composer dependencies require a php version ">= 7.3.0".
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.