Disable action add new record

Hi, I need to disable action add new record for a table when there is just another record with same userid filed, for example:
Sorry for my English!!
- Code: Select all
if ( isset($_REQUEST['-new']) ){
if ( $_REQUEST['-table'] == 'personal_info') {
$_GET['-action'] = 'list';
$_REQUEST['-action'] = 'list';
$auth =& Dataface_AuthenticationTool::getInstance();
$user =& $auth->getLoggedInUser();
$app =& Dataface_Application::getInstance();
$query = "SELECT * FROM personal_info where iduser=".$user->val('id');
$risultato = mysql_query($query,$app->db()) or die("Query fallita: " . mysql_error() );
$num_righe = mysql_num_rows($risultato);
/* Liberazione delle risorse del risultato */
mysql_free_result($risultato);
if ($num_righe <= 1)
{
$_GET['-action'] = 'list';
$_REQUEST['-action'] = 'list';
}
else
{
unset( $_REQUEST['-new']);
unset( $_GET['-new']); // disables creation of new records
}
}
}
Sorry for my English!!