I have a table that saves an ID for the user. The data for that id is gotten from LDAP
The first time the user logs in, it inserts his ID on the table. but i need to do this considering users that have data already on the database.
I get the error 
Duplicate entry 'whateverdata' for key 'PRIMARY'.
Since the field it is inserting data is Primary key. But i need to get around this.

```
$check = "select * from utilizadores where id = '$samaccountname[0]'";
$h = mysql_query($check);
if (!$h) {
  die (mysql_error());
}

$data = mysql_fetch_array($h);
if ($data[0] > 1) {
  header('location:pprincipal.php');
} 
else {
  $query = mysql_query("insert into utilizadores (id) values('$samaccountname[0]');");
  if (!$query){
    die (mysql_error());
  } 
}

```

I don't want to duplicate data, i just want to check if the data is inserted, and if it is, proceed, if it isn't, insert data.

NOTE: the $samaccountname is a variable that contains data gotten from the LDAP

basicaly - The user logs in the first time and it inserts data on the database.
The second time - Since the field is Primary Key, It will fail. 
In order to proceed to the main page (pprincipal.php) the user must have his data inserted on the database.

Thanks in advance.