Jump to content

[SOLVED] Warning: mysql_fetch_array() Error please help!


Recommended Posts

Hello! PHP Freaks community! im currently making a ip banlist for my site but i have a problem

 

i get this message on the page: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\server\www\www\thegame\no\adminban.php on line 37

 

i cant solve it, can anyone help me?

 

<?PHP











?>
<?	
include "header2.php";
include "_menu.php";
;	if ($melding) {
	echo "<div class=\"window\">";
	echo "<div class=\"mainTitle\">Logged Ip's</div>";
	echo "<div class=\"mainText\">";
	echo "$melding";
	echo "</div></div>";
} else {	
?>
<div class="window">
<div class="mainTitle">Logged Ip's</div>
<div class="mainText">
<table border=1>
	<tr><td>Brukernavn</td><td>Varsel</td><td>IP</td></tr>
	<?
	if ($moderator > 1) {
	if ($ip) {
		$lijstgebruikers = "SELECT * FROM ip_logs WHERE ip='$ip' ORDER BY id DESC";
	} else {
	$lijstGebruikers = "SELECT * FROM ip_logs ORDER BY id DESC";
}
-> /*LINE 37!!*/		$resultLijstGebruikers = mysql_query($lijstGebruikers);
	while ($row = mysql_fetch_array($resultLijstGebruikers)) {
		echo "<tr><td><a href=\"viewprofile.php?viewprofile=$row[username]\">$row[username]</a></td><td>$row[when]</td><td><a class=\"menuItem\" href=\"adminban.php?ip=$row[ip]\"><font color=green>$row[ip]</font></a></td></tr>";
	}
} else {
	echo "<b>Denne siden har du ikke tilgang til!</b>";
}
	?>

</table>
</div>
</div>
<?
}
include "footer.php";
?>

 

 

Thanks. Driiper

<?php	
include "header2.php";
include "_menu.php";
;	if ($melding) {
	echo "<div class=\"window\">";
	echo "<div class=\"mainTitle\">Logged Ip's</div>";
	echo "<div class=\"mainText\">";
	echo "$melding";
	echo "</div></div>";
} else {	
?>

 

Well for one, what is with the extra semicolon? before the if statement? And what is with the blank top part? Between those PHP tags?

 

 

Second,

 

you're really making it sloppy with closing/opening PHP tags everywhere...which is probably causing you to create simple syntax errors.

 

?>
<div class="window">
<div class="mainTitle">Logged Ip's</div>
<div class="mainText">
<table border=1>
	<tr><td>Brukernavn</td><td>Varsel</td><td>IP</td></tr>
	<?
	if ($moderator > 1) {
	if ($ip) {
		$lijstgebruikers = "SELECT * FROM ip_logs WHERE ip='$ip' ORDER BY id DESC";
	} else {
	$lijstGebruikers = "SELECT * FROM ip_logs ORDER BY id DESC";
}
-> /*LINE 37!!*/		$resultLijstGebruikers = mysql_query($lijstGebruikers);
	while ($row = mysql_fetch_array($resultLijstGebruikers)) {
		echo "<tr><td><a href=\"viewprofile.php?viewprofile=$row[username]\">$row[username]</a></td><td>$row[when]</td><td><a class=\"menuItem\" href=\"adminban.php?ip=$row[ip]\"><font color=green>$row[ip]</font></a></td></tr>";
	}
} else {
	echo "<b>Denne siden har du ikke tilgang til!</b>";
}
	?>

</table>
</div>
</div>
<?
}
include "footer.php";
?>

 

You don't need to keep coming in/out of PHP tags.

I don't think this part works in your 'if' statement since I don't see where you're checking the value of $moderator:

 

<?
	if ($moderator > 1) {
	if ($ip) {
		$lijstgebruikers = "SELECT * FROM ip_logs WHERE ip='$ip' ORDER BY id DESC";
	} else {
	$lijstGebruikers = "SELECT * FROM ip_logs ORDER BY id DESC";
}
-> /*LINE 37!!*/		$resultLijstGebruikers = mysql_query($lijstGebruikers);
	while ($row = mysql_fetch_array($resultLijstGebruikers)) {
		echo "<tr><td><a href=\"viewprofile.php?viewprofile=$row[username]\">$row[username]</a></td><td>$row[when]</td><td><a class=\"menuItem\" href=\"adminban.php?ip=$row[ip]\"><font color=green>$row[ip]</font></a></td></tr>";
	}
} else {
	echo "<b>Denne siden har du ikke tilgang til!</b>";
}
	?>

 

But, if it is and we just don't see it, then the first query would return true but your 'while' statement references the second one. Note the lowercase 'g' instead of the uppercase 'G' in the two queries.

Just to make it clear :P im a newbie :D but im trying as good as i can :P

 

Everyone starts somewhere. Good thing you're asking questions, buddy.

 

Anyway, keeping your code clean will save you tons of wasted time trobuleshooting simple syntax errrors you may waste lots of time on searching for.

 

<?php

  function testing () {
    //Whatever code goes here for this function
  }

  //And here I can output HTML without closing/opening any tags

  echo'
  <table>
    <tr><td>Hey, how ya doin\'?</td></tr>
  </table>';

  //I can continue my PHP code below

  $string = 'Today sucks balls';

  //And then output more HTML here

  echo'

  <table>
    <tr><td>'.$string.'</td></tr>
  </table>';

?>

Try this:

 

<?php
include 'header2.php';
include '_menu.php';

if($melding) {
    echo '<div class="window">';
    echo '<div class="mainTitle">Logged Ip\'s</div>';
    echo '<div class="mainText">'.$melding.'</div>';
    echo '</div>';
} else {
    echo '<div class="window">';
    echo '<div class="mainTitle">Logged Ip\'s</div>';
    echo '<div class="mainText">';
    echo '<table border=1>';
    echo '<tr><td>Brukernavn</td><td>Varsel</td><td>IP</td></tr>';
    
    if($moderator > 1) {
        if ($ip) {
            $lijstgebruikers = 'SELECT * FROM ip_logs WHERE ip="'.$ip.
                               '" ORDER BY id DESC';
        } else {
            $lijstGebruikers = 'SELECT * FROM ip_logs ORDER BY id DESC';
        }
        
        $resultLijstGebruikers = mysql_query($lijstGebruikers) or
                                 die('Error: '.mysql_error());

        while($row = mysql_fetch_assoc($resultLijstGebruikers)) {
            echo '<tr><td><a href="viewprofile.php?viewprofile='.$row['username'].
                 '">'.$row['username'].'</a></td><td>'.$row['when'].
                 '</td><td><a class="menuItem" href="adminban.php?ip='.
                 $row['ip'].'"><font color=green>'.$row['ip'].
                 '</font></a></td></tr>';
        }
    } else {
        echo '<b>Denne siden har du ikke tilgang til!</b>';
    }
    
    echo '</table></div></div>';
}

include "footer.php";
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.