How would I not include text fields of a form left blank in a MySQL update query? I understand why it’s replacing filled fields with empty strings, but I’m not sure of an efficient way to fix it. Is the best option really just a lot of if statements? Is there some kind of function I could use to disallow blank fields in my html form?
Here’s what I have so far:
//Check if record exists
if(mysql_num_rows(mysql_query("SELECT Item_Id FROM Item_t WHERE Item_Id = '$itemid'")) == 0){
die('The Item ID you entered was not found. Please go back and try again.');
}
//Update record
$update = "UPDATE Item_t SET Item_Name='$itemname', Item_Price='$itemprice' WHERE Item_Id='$itemid'";
mysql_query($update);
So basically, in this example, if you leave the field that sets $itemname blank and just update $itemprice, the price will be updated, but the name will be set to an empty string.
You can check if your strings are empty in the SQL: