Résolu Erreur Création Forum

Statut
N'est pas ouverte pour d'autres réponses.

Neziics'

Membre
Inscription
28 Mai 2014
Messages
1 513
Réactions
347
Points
1 466
RGCoins
25
Salut tout le monde,

Je suis un tuto qui date un peu et Je crée ce topic pour vous demander votre aide car quand je vais sur la page d'index de mon forum,
J'ai ces erreurs :
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Projet Nexiiz\Forum\index.php on line 71

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Projet Nexiiz\Forum\index.php on line 72

voici le code :
PHP:
<?php
//Cette page permet dafficher la liste des categories
include('config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />
  <title>Forum</title>
  </head>
  <body>
     <div class="header">
     <a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Forum" /></a>
    </div>
  <div class="content">
<?php
if(isset($_SESSION['username']))
{
$nb_new_pm = mysql_fetch_array(mysql_query('select count(*) as nb_new_pm from pm where ((user1="'.$_SESSION['userid'].'" and user1read="no") or (user2="'.$_SESSION['userid'].'" and user2read="no")) and id2="1"'));
$nb_new_pm = $nb_new_pm['nb_new_pm'];
?>
<div class="box">
   <div class="box_left">
     <a href="<?php echo $url_home; ?>">Index du Forum</a>
  </div>
   <div class="box_right">
     <a href="list_pm.php">Vos messages(<?php echo $nb_new_pm; ?>)</a> - <a href="profile.php?id=<?php echo $_SESSION['userid']; ?>"><?php echo htmlentities($_SESSION['username'], ENT_QUOTES, 'UTF-8'); ?></a> (<a href="login.php">Déconnexion</a>)
  </div>
   <div class="clean"></div>
</div>
<?php
}
else
{
?>
<div class="box">
   <div class="box_left">
     <a href="<?php echo $url_home; ?>">Index du Forum</a>
  </div>
   <div class="box_right">
     <a href="signup.php">Inscription</a> - <a href="login.php">Connexion</a>
  </div>
   <div class="clean"></div>
</div>
<?php
}
if(isset($_SESSION['username']) and $_SESSION['username']==$admin)
{
?>
   <a href="new_category.php" class="button">Nouvelle Catégorie</a>
<?php
}
?>
<table class="categories_table">
   <tr>
     <th class="forum_cat">Catégorie</th>
     <th class="forum_ntop">Sujets</th>
     <th class="forum_nrep">Réponses</th>
<?php
if(isset($_SESSION['username']) and $_SESSION['username']==$admin)
{
?>
     <th class="forum_act">Action</th>
<?php
}
?>
   </tr>
<?php
$dn1 = mysql_query('select c.id, c.name, c.description, c.position, (select count(t.id) from topics as t where t.parent=c.id and t.id2=1) as topics, (select count(t2.id) from topics as t2 where t2.parent=c.id and t2.id2!=1) as replies from categories as c group by c.id order by c.position asc');
$nb_cats = mysql_num_rows($dn1);
while($dnn1 = mysql_fetch_array($dn1))
{
?>
   <tr>
     <td class="forum_cat"><a href="list_topics.php?parent=<?php echo $dnn1['id']; ?>" class="title"><?php echo htmlentities($dnn1['name'], ENT_QUOTES, 'UTF-8'); ?></a>
  <div class="description"><?php echo $dnn1['description']; ?></div></td>
     <td><?php echo $dnn1['topics']; ?></td>
     <td><?php echo $dnn1['replies']; ?></td>
<?php
if(isset($_SESSION['username']) and $_SESSION['username']==$admin)
{
?>
     <td><a href="delete_category.php?id=<?php echo $dnn1['id']; ?>"><img src="<?php echo $design; ?>/images/delete.png" alt="Delete" /></a>
     <?php if($dnn1['position']>1){ ?><a href="move_category.php?action=up&id=<?php echo $dnn1['id']; ?>"><img src="<?php echo $design; ?>/images/up.png" alt="Faire Monter" /></a><?php } ?>
     <?php if($dnn1['position']<$nb_cats){ ?><a href="move_category.php?action=down&id=<?php echo $dnn1['id']; ?>"><img src="<?php echo $design; ?>/images/down.png" alt="Faire Descendre" /></a><?php } ?>
     <a href="edit_category.php?id=<?php echo $dnn1['id']; ?>"><img src="<?php echo $design; ?>/images/edit.png" alt="Edit" /></a></td>
<?php
}
?>
  </tr>
<?php
}
?>
</table>
<?php
if(isset($_SESSION['username']) and $_SESSION['username']==$admin)
{
?>
   <a href="new_category.php" class="button">Nouvelle Catégorie</a>
<?php
}
if(!isset($_SESSION['username']))
{
?>
<div class="box_login">
   <form action="login.php" method="post">
     <label for="username">Nom d'utilisateur</label><input type="text" name="username" id="username" /><br />
     <label for="password">Mot de passe</label><input type="password" name="password" id="password" /><br />
  <label for="memorize">Se souvenir</label><input type="checkbox" name="memorize" id="memorize" value="yes" />
  <div class="center">
    <input type="submit" value="Login" /> <input type="button" onclick="javascript:document.location='signup.php';" value="S'inscrire" />
  </div>
  </form>
</div>
<?php
}
?>
     </div>
     <div class="foot"></div>
   </body>
</html>

Comment remédier à ce pb ?
Merci

PS:(Je suis novice dans le php et j'aimerais vous demander, si vous trouver la solution donnez moi le code que je doit inscrire et surtout à quel endroit je doit l'inscrire.)
 
Tu sais envoyer une archive avec tout les fichiers du dossier ? ;)
Oui, mais j'ai l'impression(je n'en sais rien) que c'est au niveau de
PHP:
<?php
$dn1 = mysql_query('select c.id, c.name, c.description, c.position, (select count(t.id) from topics as t where t.parent=c.id and t.id2=1) as topics, (select count(t2.id) from topics as t2 where t2.parent=c.id and t2.id2!=1) as replies from categories as c group by c.id order by c.position asc');
$nb_cats = mysql_num_rows($dn1);
while($dnn1 = mysql_fetch_array($dn1))
{
?>
   <tr>
     <td class="forum_cat"><a href="list_topics.php?parent=<?php echo $dnn1['id']; ?>" class="title"><?php echo htmlentities($dnn1['name'], ENT_QUOTES, 'UTF-8'); ?></a>
  <div class="description"><?php echo $dnn1['description']; ?></div></td>
     <td><?php echo $dnn1['topics']; ?></td>
     <td><?php echo $dnn1['replies']; ?></td>
<?php
if(isset($_SESSION['username']) and $_SESSION['username']==$admin)
{
?>
     <td><a href="delete_category.php?id=<?php echo $dnn1['id']; ?>"><img src="<?php echo $design; ?>/images/delete.png" alt="Delete" /></a>
     <?php if($dnn1['position']>1){ ?><a href="move_category.php?action=up&id=<?php echo $dnn1['id']; ?>"><img src="<?php echo $design; ?>/images/up.png" alt="Faire Monter" /></a><?php } ?>
     <?php if($dnn1['position']<$nb_cats){ ?><a href="move_category.php?action=down&id=<?php echo $dnn1['id']; ?>"><img src="<?php echo $design; ?>/images/down.png" alt="Faire Descendre" /></a><?php } ?>
     <a href="edit_category.php?id=<?php echo $dnn1['id']; ?>"><img src="<?php echo $design; ?>/images/edit.png" alt="Edit" /></a></td>
<?php
}
?>
  </tr>
<?php
}
?>
 
Oui, mais j'ai l'impression(je n'en sais rien) que c'est au niveau de
PHP:
<?php
$dn1 = mysql_query('select c.id, c.name, c.description, c.position, (select count(t.id) from topics as t where t.parent=c.id and t.id2=1) as topics, (select count(t2.id) from topics as t2 where t2.parent=c.id and t2.id2!=1) as replies from categories as c group by c.id order by c.position asc');
$nb_cats = mysql_num_rows($dn1);
while($dnn1 = mysql_fetch_array($dn1))
{
?>
   <tr>
     <td class="forum_cat"><a href="list_topics.php?parent=<?php echo $dnn1['id']; ?>" class="title"><?php echo htmlentities($dnn1['name'], ENT_QUOTES, 'UTF-8'); ?></a>
  <div class="description"><?php echo $dnn1['description']; ?></div></td>
     <td><?php echo $dnn1['topics']; ?></td>
     <td><?php echo $dnn1['replies']; ?></td>
<?php
if(isset($_SESSION['username']) and $_SESSION['username']==$admin)
{
?>
     <td><a href="delete_category.php?id=<?php echo $dnn1['id']; ?>"><img src="<?php echo $design; ?>/images/delete.png" alt="Delete" /></a>
     <?php if($dnn1['position']>1){ ?><a href="move_category.php?action=up&id=<?php echo $dnn1['id']; ?>"><img src="<?php echo $design; ?>/images/up.png" alt="Faire Monter" /></a><?php } ?>
     <?php if($dnn1['position']<$nb_cats){ ?><a href="move_category.php?action=down&id=<?php echo $dnn1['id']; ?>"><img src="<?php echo $design; ?>/images/down.png" alt="Faire Descendre" /></a><?php } ?>
     <a href="edit_category.php?id=<?php echo $dnn1['id']; ?>"><img src="<?php echo $design; ?>/images/edit.png" alt="Edit" /></a></td>
<?php
}
?>
  </tr>
<?php
}
?>
Screen tes tables sql
 
Salut,
Je pense que c'est requête sql qui est mal construite, si tu souhaite compter le nombre de ligne j'utilise cette requête que je trouve plus simple.
PHP:
$requete = $db->query("select count(*) as id from ma_table");
$data = $requete->fetch();
$nombre_ligne = $data['id'];
 
Salut,
Je pense que c'est requête sql qui est mal construite, si tu souhaite compter le nombre de ligne j'utilise cette requête que je trouve plus simple.
PHP:
$requete = $db->query("select count(*) as id from ma_table");
$data = $requete->fetch();
$nombre_ligne = $data['id'];
de quelle ligne à Quelle ligne ?
 
de quelle ligne à Quelle ligne ?
J'ai pas ton code donc j'ai pas les lignes précises, mais la construction de ces deux requêtes me paraisse bizarre :/
PHP:
$nb_new_pm = mysql_fetch_array(mysql_query('select count(*) as nb_new_pm from pm where ((user1="'.$_SESSION['userid'].'" and user1read="no") or (user2="'.$_SESSION['userid'].'" and user2read="no")) and id2="1"'));
$nb_new_pm = $nb_new_pm['nb_new_pm'];
PHP:
$dn1 = mysql_query('select c.id, c.name, c.description, c.position, (select count(t.id) from topics as t where t.parent=c.id and t.id2=1) as topics, (select count(t2.id) from topics as t2 where t2.parent=c.id and t2.id2!=1) as replies from categories as c group by c.id order by c.position asc');
$nb_cats = mysql_num_rows($dn1);
while($dnn1 = mysql_fetch_array($dn1))
 
J'ai pas ton code donc j'ai pas les lignes précises, mais la construction de ces deux requêtes me paraisse bizarre :/
Ce tuto date de 2010 :
Voici
Le code Entier :
PHP:
<?php
//Cette page permet dafficher la liste des categories
include('config.php');
?>
<?php require 'header.php' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />
  <title>Forum</title>
  </head>
  <body>
     <div class="header">
     <a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Forum" /></a>
    </div>
  <div class="content">
<?php
if(isset($_SESSION['username']))
{
$nb_new_pm = mysql_fetch_array(mysql_query('select count(*) as nb_new_pm from pm where ((user1="'.$_SESSION['userid'].'" and user1read="no") or (user2="'.$_SESSION['userid'].'" and user2read="no")) and id2="1"'));
$nb_new_pm = $nb_new_pm['nb_new_pm'];
?>
<div class="box">
   <div class="box_left">
     <a href="<?php echo $url_home; ?>">Index du Forum</a>
  </div>
   <div class="box_right">
     <a href="list_pm.php">Vos messages(<?php echo $nb_new_pm; ?>)</a> - <a href="profile.php?id=<?php echo $_SESSION['userid']; ?>"><?php echo htmlentities($_SESSION['username'], ENT_QUOTES, 'UTF-8'); ?></a> (<a href="login.php">Déconnexion</a>)
  </div>
   <div class="clean"></div>
</div>
<?php
}
else
{
?>
<div class="box">
   <div class="box_left">
     <a href="<?php echo $url_home; ?>">Index du Forum</a>
  </div>
   <div class="box_right">
     <a href="signup.php">Inscription</a> - <a href="login.php">Connexion</a>
  </div>
   <div class="clean"></div>
</div>
<?php
}
if(isset($_SESSION['username']) and $_SESSION['username']==$admin)
{
?>
   <a href="new_category.php" class="button">Nouvelle Catégorie</a>
<?php
}
?>
<table class="categories_table">
   <tr>
     <th class="forum_cat">Catégorie</th>
     <th class="forum_ntop">Sujets</th>
     <th class="forum_nrep">Réponses</th>
<?php
if(isset($_SESSION['username']) and $_SESSION['username']==$admin)
{
?>
     <th class="forum_act">Action</th>
<?php
}
?>
   </tr>
<?php
$dn1 = mysql_query('select c.id, c.name, c.description, c.position, (select count(t.id) from topics as t where t.parent=c.id and t.id2=1) as topics, (select count(t2.id) from topics as t2 where t2.parent=c.id and t2.id2!=1) as replies from categories as c group by c.id order by c.position asc');
$nb_cats = mysql_num_rows($dn1);
while($dnn1 = mysql_fetch_array($dn1))
{
?>
   <tr>
     <td class="forum_cat"><a href="list_topics.php?parent=<?php echo $dnn1['id']; ?>" class="title"><?php echo htmlentities($dnn1['name'], ENT_QUOTES, 'UTF-8'); ?></a>
  <div class="description"><?php echo $dnn1['description']; ?></div></td>
     <td><?php echo $dnn1['topics']; ?></td>
     <td><?php echo $dnn1['replies']; ?></td>
<?php
if(isset($_SESSION['username']) and $_SESSION['username']==$admin)
{
?>
     <td><a href="delete_category.php?id=<?php echo $dnn1['id']; ?>"><img src="<?php echo $design; ?>/images/delete.png" alt="Delete" /></a>
     <?php if($dnn1['position']>1){ ?><a href="move_category.php?action=up&id=<?php echo $dnn1['id']; ?>"><img src="<?php echo $design; ?>/images/up.png" alt="Faire Monter" /></a><?php } ?>
     <?php if($dnn1['position']<$nb_cats){ ?><a href="move_category.php?action=down&id=<?php echo $dnn1['id']; ?>"><img src="<?php echo $design; ?>/images/down.png" alt="Faire Descendre" /></a><?php } ?>
     <a href="edit_category.php?id=<?php echo $dnn1['id']; ?>"><img src="<?php echo $design; ?>/images/edit.png" alt="Edit" /></a></td>
<?php
}
?>
  </tr>
<?php
}
?>
</table>
<?php
if(isset($_SESSION['username']) and $_SESSION['username']==$admin)
{
?>
   <a href="new_category.php" class="button">Nouvelle Catégorie</a>
<?php
}
if(!isset($_SESSION['username']))
{
?>
<div class="box_login">
   <form action="login.php" method="post">
     
     <div class="form-group">
<div align="left">
<label for="">Pseudo :</label>
<input type="username" name="username"  id="username" class="form-control"/>
</div>
</div>
         <div class="form-group">
<div align="left">
<label for="">Mot de passe :</label>
<input type="password" name="password"  id="password" class="form-control"/>
</div>
</div>
  <label for="memorize">Se souvenir</label><input type="checkbox" name="memorize" id="memorize" value="yes" /> <br>
  <div class="left">
    <br/>
       <p>Pas Encore Membre ?  <a href="http://127.0.0.1/Projet%20Nexiiz/Espace%20Membre/sign_up.php" class="myButton1">Inscription</a></p>
       
  </div>
  </form>
</div>
<?php
}
?>
     </div>
     <div class="foot"></div>
   </body>
</html>
Si tu as besoin d'un autre fichier dis le moi
 
$dn1 = mysql_query('select c.id, c.name, c.description, c.position, (select count(t.id) from topics as t where t.parent=c.id and t.id2=1) as topics, (select count(t2.id) from topics as t2 where t2.parent=c.id and t2.id2!=1) as replies from categories as c group by c.id order by c.position asc');
$nb_cats = mysql_num_rows($dn1);
while(
$dnn1 = mysql_fetch_array($dn1))
{
Refait cette requête en la mettant a jour par toi même car je pense qu'il ne comprend pas le fait que tu veuille compter et sélectionner des éléments sql en même temps.
Voici une site avec des informations sur la construction de requête PDO
 
Refait cette requête en la mettant a jour par toi même car je pense qu'il ne comprend pas le fait que tu veuille compter et sélectionner des éléments sql en même temps.
Voici une site avec des informations sur la construction de requête PDO
J y comprends rien, tu peut pas me dire quel est le code final ?
 
J y comprends rien, tu peut pas me dire quel est le code final ?
C'est toi qui a le code complet, je connais pas ce que tu as fais et le but des différentes requêtes, seul toi sais ce qu'il faut compter et sélectionner, c'estpas compliqué tu fais une requête select pour les champ qui sont dans ta sql et une autre requête pour ce que tu veux compter ;)
 
C'est toi qui a le code complet, je connais pas ce que tu as fais et le but des différentes requêtes, seul toi sais ce qu'il faut compter et sélectionner, c'estpas compliqué tu fais une requête select pour les champ qui sont dans ta sql et une autre requête pour ce que tu veux compter ;)
Je sais pas faire X) (je suis null(je te fournis le code complet si tu veut :)))
 
Je sais pas faire X) (je suis null(je te fournis le code complet si tu veut :)))
Il est l'heure d'apprendre, c'est pas faisant faire le code a une autre personne que tu arriveras a faire quelque chose par toi même, si tu as des questions je répondrais a celle-ci.
 
Statut
N'est pas ouverte pour d'autres réponses.
Retour
Haut