954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

MySQL error showing when they shouldn't

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] <?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"; ?> Oggi é <?php echo date("l j F Y, g:i"); ?>
<?php switch($_GET['lev']){ case 0: echo "Forum Pubblico"; break; case 1: echo "Forum Privato"; break; case 2: echo "Forum Moderatori"; break; } ?> View unanswered posts   <?php switch($_GET['lev']){ case 0: echo "Forum Pubblico"; break; case 1: echo "Forum Privato"; break; case 2: echo "Forum Moderatori"; break; } ?>    Threads   Posts   Ultimo Post  <?php while ($gr=mysql_fetch_assoc($res)){ extract($gr); ?> <?php echo $forumsects_name; ?>   <?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']; ?> No new posts<?php echo $forums_name; ?>
<?php echo $forums_descr; ?>
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 "".$modnm." "; } ?> <?php echo $forums_threads; ?> <?php echo $forums_posts; ?> <?php echo $lastdt; ?>
<?php echo $lsusnm; ?> View latest post <?php } } ?> All times are GMT <?php require "../includes/footer.inc.php"; ?> [/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['lev']."' 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

Astegiano
Newbie Poster
9 posts since May 2006
Reputation Points: 10
Solved Threads: 1
 

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

sunflowerz
Newbie Poster
16 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

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.

sn4rf3r
Junior Poster
135 posts since Sep 2006
Reputation Points: 10
Solved Threads: 2
 

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.

Astegiano
Newbie Poster
9 posts since May 2006
Reputation Points: 10
Solved Threads: 1
 

is there a difference in
[php]
$forumsects_id
[/php]
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?

sn4rf3r
Junior Poster
135 posts since Sep 2006
Reputation Points: 10
Solved Threads: 2
 

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!!

Astegiano
Newbie Poster
9 posts since May 2006
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You