With **$exists = ($exists ? true : false);**

- If $exixts is true, it will turned to true, 
- if $exists is false (default) it wll be turned to false.
=> it will never changed. 

Did you wanted to write :
```
foreach($dbresult as $row) {
    if (($row['dn_type_vc'] == 'A' && $type[$NewId] == 'AAAA') OR 
        ($row['dn_type_vc'] == 'AAAA' && $type[$NewId] == 'A')) {
            $exists = true;
            break;  //once one already exists it is wrong
         }
    }
```
BTW, I'm not sure that a such cross search between A and AAAA is required. I am feeling that a simple query for host name where type = A or type = AAAA  would be enough : if any hostname already exists -> error.
Something like this:
```
    $numrows = $zdbh->prepare('SELECT dn_id_pk FROM x_dns WHERE (dn_type_vc="A" OR dn_type_vc="AAAA" ) AND dn_host_vc=:hostName2 AND dn_vhost_fk=:domainID AND dn_deleted_ts IS NULL');
```
But I have not time enough to search more in details or test.  :-(