...

View Full Version : php mysql error



Killermud
05-10-2009, 06:14 PM
I have a script that stores and removes sessions on my website, but for some reason i get this error sometimes, even though the script is run correctly.


Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\domains\opjeplaats.nl\wwwroot\darkness\Webtemp\includes\sessions.php on line 84

Here is where the problem is (arrows indicate the error) :


$sql="SELECT * FROM rfd_sessions";
$result=mysql_query($sql);
$ip=$_SERVER['REMOTE_ADDR'];
$count=mysql_num_rows($result);
if($count>0){
--->while($rows=mysql_fetch_assoc($result)){

And


$sql="SELECT * FROM rfd_sessions WHERE user_ip='$ip'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count > 1){
--->while($rows=mysql_fetch_assoc($result)){

When i reload the page the error does not appear, how can i make the errors stop coming up?

CFMaBiSmAd
05-10-2009, 06:30 PM
Since you are checking that there is at lest one row in the result set, it is highly likely that your code inside the while(){} loop is overwriting the $result variable. You would need to post your code for the whole while loop to get help with what it might be doing.

Killermud
05-10-2009, 06:52 PM
Ok well the first while loop is :


if($count>0){
while($rows=mysql_fetch_assoc($result)){
if(time()-$rows['lastaction_time'] >= 300){
// Remove visitors completely to relief space on DB
if($rows['user_id'] == 0){
$ip=$rows['user_ip'];
$sql="DELETE FROM rfd_sessions WHERE user_ip='$ip'";
$result=mysql_query($sql);
}elseif($rows['user_id'] != 0 && $rows['logged'] == 1){
$id=$rows['user_id'];
$time=$rows['lastaction_time'];
$sql="UPDATE rfd_sessions SET lastvisit_time='$time', logged=0 WHERE user_id='$id'";
$result=mysql_query($sql);
}
}

2nd :


if($count > 1){
while($rows=mysql_fetch_array($result)){
if($rows['logged'] == 1){
$sql="DELETE FROM rfd_sessions WHERE user_ip='$ip' AND user_id=0";
$result=mysql_query($sql);
}
}

CFMaBiSmAd
05-10-2009, 07:03 PM
So, like was already guessed, don't you suppose reusing the $result variable inside of the while() loops for a different query would affect the outer while loops?

Killermud
05-10-2009, 07:29 PM
Oh yeah, thanks for pointing that out, not sure how i missed than :confused:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum