Hello,
I'm building a website like MySpace, the address is http://pantarei.awardspace.com the website is wrote in Italian. It has members customizable profiles, internak message system, search user tools, a forum and a chat.

I just builded the main forum page but I have a problem that I cannot solve. The forum is divided in 3 different section, based on authorzation: one is visable by everybody, one just by who is logged in and one just by the modarators and admins. The tre sections are showed all by the same pae that gets from the url the level of the forum, check the authorization and then show it.

When I open the forum without being logged in it works fine, but when I open it being logged in the first query gives out a different result that mysql_fetch_assoc is unable to read.

The login system is made with database stored variable, one with the id of the user and the other one with the authorization. I don't understand how can this influence the forum.

The main forum page's code is:

<?php
require_once "../includes/session_handler.inc.php";
require "../includes/functions.inc.php";
session_start();
$_SESSION['pgnm']="Forum";
$_SESSION['pgsec']="5";
$conn=connect_db();
if ((!isset($_GET['lev'])) or ($_GET['lev']==3)){
 header ("Location: ".ADRESS."/forum.php");
 exit;
}
if (isset($_SESSION['auth'])){
 if ($_GET['lev']>$_SESSION['auth']){
  header ("Location: ".ADRESS."/forum.php");
  exit;
 }
} elseif ($_GET['lev']!=0){
 header ("Location: ".ADRESS."/forum.php");
 exit;
}
$res=mysql_query("SELECT * FROM forumsects WHERE forumsects_lev='".$_GET['lev']."' ORDER BY forumsects_order", $conn) or die(mysql_error());
require "../includes/header.inc.php";
?>
<table width="95%" cellspacing="0" cellpadding="2" border="0" align="center">
 <tr>
  <td align="left" valign="bottom"><span class="gensmall">
   Oggi é <?php echo date("l j F Y, g:i"); ?><br /></span><span class="nav"><a href="../forum/showforum.php?lev=<?php echo $_GET['lev']; ?>" class="nav">
   <?php switch($_GET['lev']){
    case 0:
     echo "Forum Pubblico";
    break;
    case 1:
     echo "Forum Privato";
    break;
    case 2:
     echo "Forum Moderatori";
    break;
   } ?>
   </a></span>
  </td>
  <td align="right" valign="bottom" class="gensmall">
   <a href="searchthreads.php?id=unanswered" class="gensmall">View unanswered posts</a>
  </td>
 </tr>
</table>
<table width="95%" cellpadding="2" cellspacing="1" border="0" class="forumline" align="center">
 <tr>
  <th colspan="2" class="thCornerL" height="30" nowrap="nowrap">&nbsp;
  <?php switch($_GET['lev']){
   case 0:
    echo "Forum Pubblico";
   break;
   case 1:
    echo "Forum Privato";
   break;
   case 2:
    echo "Forum Moderatori";
   break;
  } ?>
  &nbsp;</th>
  <th width="50" class="thTop" nowrap="nowrap">&nbsp;Threads&nbsp;</th>
  <th width="50" class="thTop" nowrap="nowrap">&nbsp;Posts&nbsp;</th>
  <th class="thCornerR" nowrap="nowrap">&nbsp;Ultimo Post&nbsp;</th>
 </tr>
 <?php while ($gr=mysql_fetch_assoc($res)){
  extract($gr);
  ?>
  <tr>
   <td class="catLeft" colspan="2" height="30"><span class="cattitle"><?php echo $forumsects_name; ?></span></td>
   <td class="rowpic" colspan="3" align="right">&nbsp;</td>
  </tr>
  <?php
  $re=mysql_query("SELECT * FROM forums WHERE forums_sect='".$forumsects_id."' ORDER BY forums_order", $conn);
  while ($fr=mysql_fetch_assoc($re)){
   extract($fr);
   $mod=explode("|", $forums_admins);
   $lastdt=date("l j F Y, g:i", mktime($forums_lsdate['11'].$forums_lsdate['12'], $forums_lsdate['14'].$forums_lsdate['15'], 0, $forums_lsdate['5'].$forums_lsdate['6'], $forums_lsdate['8'].$forums_lsdate['9'], $forums_lsdate['0'].$forums_lsdate['1'].$forums_lsdate['2'].$forums_lsdate['3']));
   $us=mysql_query("SELECT login_user FROM login WHERE login_id='".$forums_lsuser."'", $conn);
   $arr=mysql_fetch_assoc($us);
   $lsusnm=$arr['login_user'];
   ?>
   <tr>
    <td class="row1" align="center" valign="middle" height="50"><img src="../images/forum/folder_big.gif" width="46" height="25" alt="No new posts" title="No new posts" /></td>
    <td class="row1" width="100%" height="50">
     <span class="forumlink"> <a href="viewforum.php?f=14&amp;style=269" class="forumlink"><?php echo $forums_name; ?></a><br /></span>
     <span class="genmed"><?php echo $forums_descr; ?><br /></span>
     <span class="gensmall">Moderators 
     <?php foreach($mod as $m){
     $d=mysql_query("SELECT login_user FROM login WHERE login_id='".$m."'", $conn);
     $arr=mysql_fetch_assoc($d);
     $modnm=$arr['login_user']; 
     echo "<a href=\"../mypage/showpage.php?id=".base64_encode($m)."\">".$modnm."</a> ";
     } ?>
     </span>
    </td>
    <td class="row2" align="center" valign="middle" height="50"><span class="gensmall"><?php echo $forums_threads; ?></span></td>
    <td class="row2" align="center" valign="middle" height="50"><span class="gensmall"><?php echo $forums_posts; ?></span></td>
    <td class="row2" align="center" valign="middle" height="50" nowrap="nowrap">
     <span class="gensmall"><?php echo $lastdt; ?><br />
      <a href="../mypage/showpage.php?id=<?php echo base64_encode($forums_lsuser); ?>"><?php echo $lsusnm; ?></a>
      <a href="../forum/openthread.php?th=<?php echo base64_encode($forums_lspost); ?>">
      <img src="../images/forum/icon_latest_reply.gif" border="0" alt="View latest post" title="View latest post" /></a>
     </span>
    </td>
   </tr>
  <?php
  }
 }
?>
</table>
<table width="95%" cellspacing="0" border="0" align="center" cellpadding="2" align="center">
  <tr>
  <td align="left">
  </td>
 <td align="right"><span class="gensmall">All times are GMT</span></td>
  </tr>
</table>
<?php
require "../includes/footer.inc.php";
?>

You can try the problem by logging in with the username "prova" and password "prova".

The first query $res=mysql_query("SELECT * FROM forumsects WHERE forumsects_lev='".$_GET."' ORDER BY forumsects_order", $conn) or die(mysql_error()); give out two different values (when it works 6, when it doesn't 8).

I hope you can find the problem.
Astegiano

Hi Astengiano!

I have had a quick look, but I have not created/seen anything like this, so I can't see any errors in the code...sorry.

The error relates to mysql_fetch_assoc() so you could try looking at the php.net website and reading that function's information.

This may or may not be helpful, but I hope that it is.

- sunflowerz

have you tied echoing out the query and running it from the command line and/or mysqladmin? also you arent checking to see if you even have any results from the query, if this is empty you will get an error when trying to run mysql_fetch_array on an empty result.
Start with your query and go from there.

I alredy tryed echoing the query and executing it in phpmyadmin and it works. I printed the result of the query when I'm not logged in and it's 6 , but when I'm logged in it became 8. I tryed everything I can think of.
Thank you anyway.

is there a difference in

$forumsects_id

when you are logged in an when you are not? Have you tried echoing things out inside the while loops to make sure you are even getting there? do you have error logging turned on?

I found the error... it was stupid. Somehow the variable in wich I was trying to put the result of the query had alredy another result and that caused some kind of problem.
Thank you everybody!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.