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

PHP Mysql, assign a default value if user submit empty

user1367 Published in July 18, 2018, 12:41 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.

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"]."';";


	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.313894 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO