Drupal 6: Prevent the user from creating more than one node (of a certain type)

Last year I wrote a quick code snippet to prevent the user from creating more than one node of a certain type for Drupal 5. I received a comment request to update this code for Drupal 6.

<?php
function MYMODULE_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {

  // define node type that a user will only be allowed to create one instance of
  $singleNodeType = 'YOUR-NODE-TYPE';

  // test for node/add/NODETYPE page
  if ($node->type==$singleNodeType && $op=='prepare' && arg(0)=='node' && arg(1)=='add') {

    // define sql to create node table
    $sql = "select nid from {node} where type='%s' and uid='%d'";

    // execute sql
    $resource = db_query($sql, $singleNodeType, db_escape_string($GLOBALS['user']->uid));
    $result = db_result($resource);

    // test for result
    if (!empty($result)) {

      // set a message
      drupal_set_message("Sorry, you are only allow to create one $singleNodeType.");

      // redirect the user
      drupal_goto('node/add');

    }

  }

}
?>

The above code tests if the user is on the node/add/NODETYPE page and if the user has already created an instance of the node type, sets a message and redirects them away from the node/add page.