Jump to content

if x=?? do this, or if y=?? do this


woodplease

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.