I am having an error when querying the id in a table, I am developing a system of friendship between users and the error is as follows:
PDOException: SQLSTATE [23000]: Integrity constraint violation: 1062 Duplicate du champ '0' pour la clef 'PRIMARY' in C: \ wamp \ www \ sllap \ php \ amisade.php on line 14
See:
$is_my_friend = DB::getConn()->prepare('SELECT * FROM 'friends' WHERE (de=? AND para=?) OR (para=? AND de=?) LIMIT 1');
$is_my_friend->execute(array($idDaSessao,$idExtrangeiro,$idDaSessao,$idExtrangeiro));
if($is_my_friend->rowcount()==0){
echo'<a class="addFriend" href="php/amisade.php?ac=addfriend&de='.$idDaSessao.'¶='.$idExtrangeiro.'">Adicionar aos amigos</a>';
}else{
$astatusfriend = $is_my_friend->fetch(PDO::FETCH_ASSOC);
if($astatusfriend['status']==0){
echo'<a class="deleteFriend" href="php/amisade.php?ac=cancel&id='.$astatusfriend['id'].'&de='.$idDaSessao.'¶='.$idExtrangeiro.'">cancelar solicitação enviada</a>';
}
}
amisade.php page:
include('../classes/DB.class.php');
if(''<>$_GET['ac']){
if($_GET['ac']=='addfriend'){
$is_my_friend = DB::getConn()->prepare('SELECT * FROM 'friends' WHERE (de=? AND para=?) OR (para=? AND de=?)');
$is_my_friend->execute(array($_GET['de'],$_GET['para'],$_GET['de'],$_GET['para']));
if($is_my_friend->rowCount()==0){
$addfriend = DB::getConn()->prepare('INSERT INTO 'friends' SET 'de'=?,'para'=?');
$addfriend->execute(array($_GET['de'],$_GET['para']));
header('Location: ../profile.php?uid='.$_GET['para']);
}
}
}
if($_GET['ac']=='cancel'){
$is_my_friend = DB::getConn()->prepare('SELECT * FROM 'friends' WHERE (de=? AND para=?)OR(para=? AND de=?) LIMIT 1');
$is_my_friend->execute(array($_GET['de'],$_GET['para'],$_GET['de'],$_GET['para']));
if($is_my_friend->rowCount()==1){
$addfriend = DB::getConn()->prepare('DELETE FROM 'friends' WHERE 'id'=?');
$addfriend->execute(array($_GET['id']));
header('Location: ../profile.php?uid='.$_GET['para']);
}
}