I have custom code in my page.tpl.php file:

$mybionode = node_load(bio_for_user($user->uid));

Unfortunately, it gives the following errors when a user hasn't already filled out their bio information:

* warning: Invalid argument supplied for foreach() in node.module on line 537.
* warning: implode(): Bad arguments. in node.module on line 541.
* user warning: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 query: node_load SELECT n.nid, n.vid,

I guess you can't load a node if it doesn't exist. Is there a way to check if a node exists before I call node_load? I don't see anything in the API. I could do an SQL check but I'm wary of running too many queries (I suppose the API would have to run a query anyhow).

Comments

Allie Micka’s picture

Status: Active » Closed (fixed)

That's correct, you can't load a node that doesn't exist. But you CAN see if it exists before loading it. Try the following code:

if ($nid = bio_for_user($user->uid)) {
$mybionode = node_load($nid);
}

Of course, you'll have to account for an empty $mybionode in the remainder of your code.

Thanks!