Home PHP Mysql, assign a default value if user submit empty
Reply: 0

PHP Mysql, assign a default value if user submit empty

user1367
1#
user1367 Published in June 20, 2018, 7:26 am

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?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.322878 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO