Système de follow de PrimFX ---> Pb BDD

Suivre ce topic
Ce topic est suivi par : Personne...
Ce topic a été résolu
Balatharas

Balatharas Le 15 juin 2016 à 15:53 (Édité le 25 janvier 2019 à 17:51)

Bonjour, j'ai un problème jai fait un code pour un système de follow a l'aide du tuto de @PrimFXhttps://youtu.be/yUNdY_R9F84
Mais rien ne se passe dans ma base de données. Voilà mon code:
follow.php
<?php
   session_start();
   require ('config.php');
   if(isset($_GET['followedid']) AND !empty($_GET['followedid'])) {
      $getfollowedid = intval($_GET['followedid']);
      if($getfollowedid != $_SESSION['id']) {
         $dejafollowed = $bdd->prepare('SELECT * FROM follow WHERE id_follower = ? AND if_following = ?');
         $dejafollowed->execute(array($_SESSION['id'], $getfollowedid));
         $dejafollowed = $dejafollowed->fetch();
         if($dejafollowed) {
            $addfollow = $bdd->prepare('INSERT INTO follow(id_follower, id_following) VALUES (?, ?)');
            $addfollow->execute(array($_SESSION['id'], $getfollowedid));
         } else($dejafollowed == 1) {
            $deletefollow = $bdd->prepare('DELETE FROM follow WHERE id_follower = ? AND id_following = ?');
            $deletefollow->execute(array($_SESSION['id'], $getfollowedid));
         }
      }
   }
   header('Location: '.$_SERVER['HTTP_REFERER']);
?>
profil.php => Entrée pour follow:
<?php
if(isset($_SESSION['id']) AND $_SESSION['id'] != $getid)
{
?>
<a href="follow.php?followedid=<?= $getid; ?>"><font size="4">Suivre</font></a>
<?php
}
?>
Base de données:
id (index primaire + auto-increment)
id_follower
id_following
Je n'ai aucune erreur: page blanche.
Pourrais-tu m'aider @PrimFX ?

Merci d'avance !
Dwardower

Dwardower Le 15 juin 2016 à 15:59

<?= $getid; ?>
heu, soit j'ai loupé quelque chose soit ce type de code n'existe pas ^^
<?php echo $getid; ?>
serait plus correct
TheOldNoob

TheOldNoob Le 15 juin 2016 à 16:16

<?= est un raccourci de <?php echo

:)
Balatharas

Balatharas Le 15 juin 2016 à 16:41

Merci ^.^ @TheHoldNoob
Sinon personne pour mon problème ?
Dwardower

Dwardower Le 15 juin 2016 à 16:42

okay merci, je n'avais jamais vu ça ^^'
PaulLavieille

PaulLavieille Le 15 juin 2016 à 22:36

Pour ton follow.php essaye ce code :

<?php
 session_start();
require ('config.php');
<?php
 $getfollowedid = intval($_GET['followedid']);
 if($getfollowedid != $_SESSION['id']) {
    $dejafollowed = $bdd->prepare('SELECT * FROM follow WHERE  id_follower = ? AND id_following = ? ' );
    $dejafollowed->execute(array($_SESSION['id'], $getfollowedid));
    $dejafollowed = $dejafollowed->rowCount();
    if($dejafollowed == 0) {
       $addfollow = $bdd->prepare('INSERT INTO follow(id_follower, id_following) VALUES(?, ?)');
       $addfollow->execute(array($_SESSION['id'],$getfollowedid));
  }   elseif ($dejafollowed == 1) { 
       $deletefollow = $bdd->prepare('DELETE FROM follow WHERE id_follower = ? AND id_following = ?');
       $deletefollow->execute(array($_SESSION['id'],$getfollowedid));
    }
 }
    header('Location:' .$_SERVER['HTTP_REFERER']);
?>
Tiens moi au courant 😉
Balatharas

Balatharas Le 16 juin 2016 à 18:48

@PaulLavieille Merci ça marche  ! Mais euh... c'était quoi l'erreur 😰 ?
PaulLavieille

PaulLavieille Le 17 juin 2016 à 15:32

@Beignet Super ! 
À la ligne 9 c'est un RowCount et pas un fetch, sinon je sais plus si c'était la seule erreur ou non 😠
Balatharas

Balatharas Le 18 juin 2016 à 14:05

Ok merci 😄 @PaulLavieille 
Vous devez être connecté pour poster une réponse. Se connecter ou Créer un compte