Souci de "if" help please

Résolu
Bonjour, tous d'abord, voici mon code :

$verif_clan = $bdd->query("SELECT clan FROM membres WHERE ID='".$ID."'");
$ok = $verif_clan->fetch();
if ($ok == 0)
{
?>

<center>Création d'un clan (coût : 15 000P$)</center>
 <form method="post" action="">
  <div>
    <div>Nom du clan:</div>
   <div><input type="text" name="nom" size="20" maxlength="255"></div>
   <div>Chef du clan:</div>
   <div><input type="text" name="chef" size="20" maxlength="255"></div>
   <div>Slogan :</div>
   <div><input type="text" name="slogan" size="50" maxlength="120"></div>
   <div>Déscription :</div>
   <div><input type="text" name="description" size="100" maxlength="10000"></div>
   <div>Image du clan :</div>
   <div><input type="text" name="image" size="100" maxlength="255"></div>
  </div>
  <div class="bouton"><input type="submit" value="Valider"></div>
 </form>
 <?php
 if (isset($_POST['chef']) AND isset($_POST['nom']))
 {
 $chef = htmlentities($_POST['chef']);
 $nom = htmlentities($_POST['nom']);
 $slogan = htmlentities($_POST['slogan']);
 $description = htmlentities($_POST['description']);
 $image = htmlentities($_POST['image']);
 $date = time();
 if (empty($chef))
 {
  echo ("saississez le chef du clan");
  exit();
 }
 if (empty($nom))
 {
  echo ("saississez le nom du clan");
  exit();
 }
 $creation_clan = $bdd->prepare("INSERT INTO clans VALUES ('', :nom, :chef, :slogan, '1', :description, :date, '0', '0', :image, '0')");
 $creation_clan->bindValue(':nom', $nom, PDO::PARAM_INT);
 $creation_clan->bindvalue(':chef', $chef, PDO::PARAM_INT);
 $creation_clan->bindvalue(':slogan', $slogan, PDO::PARAM_INT);
 $creation_clan->bindvalue(':description', $description, PDO::PARAM_INT);
 $creation_clan->bindvalue(':date', $date, PDO::PARAM_INT);
 $creation_clan->bindvalue(':image', $image, PDO::PARAM_INT);
 $creation_clan->execute();
 $chef_clan = $bdd->exec("UPDATE membres SET clan = 1 WHERE ID='".$ID."'");
 }
 }
 else
 {
 echo "Vous avez déjà un clan, quittez-le ou dissolvez-le si vous souhaitez en créer un!!!";
 }
 ?>


Alors voila, ce code ne me donne pas d'erreur mais lorsque le champ "clan" contient "1", il ne m'affiche pas le formulaire donc c'est normal, par contre même si le champ "clan" comporte "0", il ne me l'affiche pas là, pas normal.

Donc mon souci est que si j'ai 1 il s'affiche pas et si j'ai 0 il doit s'afficher ce qu'il ne fait pas.

Pouvez-vous m'aider ?

Merci par avance.

3 réponses

  1. Merci pour vos réponses et oui en effet j'avais pas fais attention à ça.

    Ca fonctionne en effet ;)
    1. Bonjour

      Attention, le résultat d'un fetch (quand il n'est pas FALSE) est un tableau. Ce n'est donc pas $ok qu'il faut tester, mais, comme tu t'intéresse au champ clan :
      if( $ok['clan']==0)
      1. Il ne faut pas mettre de quotes après le WHERE id car id est un int, les quote c'est pour string/char.
        1. Bonjour

          C'est vrai mais ça n'est pas grave car mysql fait automatiquement le changement de type. La requête marche très bien avec des quotes.