Welcome Guest, Not a member yet? Register   Sign In
Undefined variable error short workaround help
#1

[eluser]Unknown[/eluser]
I have a conditional statement that will print a defined value if the db field is null, but if the user is about to create a new record the db query isnt run so i get an undefiend varibale error were i would like it to just assume that the variable is null.

Code:
($info->title == '' ? 'Add title' : $info->title)

Can anyone recommend a way to write this while keeping it as short as possible.

Cheers
#2

[eluser]iloveci[/eluser]
I believe you want to use isset() http://php.net/manual/en/function.isset.php. Also I wouldn't worry about making code 'short' as it's far more important that your code is readable.




Theme © iAndrew 2016 - Forum software by © MyBB