woodplease Posted December 18, 2010 Share Posted December 18, 2010 hi, i'm trying to create an "if" statement that will add a value to a variable if it returns empty, e.g. if $year returns empty, set $year to "unknown", or if $certificate returns empty, set $certificate to unknown the code i have so far if (empty($year)) { $year="unknown"; } elseif (empty($certificate)) { $certificate="unknown"; } mysql_query("INSERT INTO films (title, year, certificate, date_added) VALUES ('$title','$year','$certificate','$date')") or die("Unable to add film<br/><a href='./add_film.php'>Back</a><br/>" .mysql_error()); when it $certficate returns empty, it will change the value to unknown, but when $year returns empty, it doesnt change its value. Any help would be great Link to comment https://forums.phpfreaks.com/topic/222089-if-x-do-this-or-if-y-do-this/ Share on other sites More sharing options...
BlueSkyIS Posted December 18, 2010 Share Posted December 18, 2010 it would help to see where $year comes from, but try seeing what's in it by using var_dump to see if $year is actually empty() var_dump($year); if $year is empty AND $certificate is empty, only $year is set to "unknown". you might want to exchange that elseif for a regular if Link to comment https://forums.phpfreaks.com/topic/222089-if-x-do-this-or-if-y-do-this/#findComment-1149062 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.