I'm trying to give a default value if the user submit an empty value like [{"photourl":""}] using php and mysql query. I'm not really familiar with backend so i'm not sure my code is correct or not.
<?php
function profile_put($dt)
{
$query="update personal set fullname='".$dt[0]["name"]."', dob='".$dt[0]["dob"]."',
gender='".$dt[0]["gender"]."', country='".$dt[0]["country"]."', city='".$dt[0]["city"]."', photourl='".$dt[0]["photourl"]."',
lastupdate='15 minutes', about='', website=''
where huffid='".$dt[0]["huffid"]."';";
if($dt[0]["photourl"]=="")
{
$dt[0]["photourl"]='https://i.imgur.com/KbHbcqV.png';
}
return $query;
}
?>
Then i tried the API using postman, the body looks like this
[{
"huffid":"newuser",
"dob":"121212",
"gender":"male",
"country":"singapore",
"city":"singapore",
"photourl": ""
}]
From the frontend, if the user doesn't give any photo the photourl will empty just like what i sent using postman. The photourl in database column also emoty. Can anyone help, please?