Drupal 5: Prevent the user from creating more than one node (of a certain type)
In certain situations you may want to prevent the user from creating more than one node (of a certain type). This can be accomplished using the hook_nodeapi:
<?php
function MYMODULE_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
// ...some code...
if ($node->type=='YOURNODETYPE' && 'op'=='prepare' && $_REQUEST['q']=='node/add/YOURNODETYPE') {
$sql = "select nid from {node} where type='YOURNODETYPE' and uid='%d' and status='1'";
$resource = db_query($sql, db_escape_string($GLOBALS['user']->uid));
$result = db_result($resource);
if ($result) drupal_goto('SOMELOCATION');
}
// ...some code...
?>
NOTE: the above code will prevent the user from adding another node by redirecting them away from the node/add page