Driiper Posted January 3, 2008 Share Posted January 3, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/84355-solved-warning-mysql_fetch_array-error-please-help/ Share on other sites More sharing options...
Caesar Posted January 3, 2008 Share Posted January 3, 2008 <?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? Quote Link to comment https://forums.phpfreaks.com/topic/84355-solved-warning-mysql_fetch_array-error-please-help/#findComment-429651 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 Add a mysql_error() after your query so you can see why your result failed. Change your short <? tags to <?php tags as well. Quote Link to comment https://forums.phpfreaks.com/topic/84355-solved-warning-mysql_fetch_array-error-please-help/#findComment-429657 Share on other sites More sharing options...
phpSensei Posted January 3, 2008 Share Posted January 3, 2008 You have crap floating everywhere in your script, like that ";" ... and <?" short tags/ Quote Link to comment https://forums.phpfreaks.com/topic/84355-solved-warning-mysql_fetch_array-error-please-help/#findComment-429659 Share on other sites More sharing options...
Caesar Posted January 3, 2008 Share Posted January 3, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84355-solved-warning-mysql_fetch_array-error-please-help/#findComment-429660 Share on other sites More sharing options...
Driiper Posted January 3, 2008 Author Share Posted January 3, 2008 Just to make it clear im a newbie but im trying as good as i can Quote Link to comment https://forums.phpfreaks.com/topic/84355-solved-warning-mysql_fetch_array-error-please-help/#findComment-429662 Share on other sites More sharing options...
simcoweb Posted January 3, 2008 Share Posted January 3, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84355-solved-warning-mysql_fetch_array-error-please-help/#findComment-429665 Share on other sites More sharing options...
Caesar Posted January 3, 2008 Share Posted January 3, 2008 Just to make it clear im a newbie but im trying as good as i can 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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/84355-solved-warning-mysql_fetch_array-error-please-help/#findComment-429672 Share on other sites More sharing options...
duclet Posted January 3, 2008 Share Posted January 3, 2008 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/84355-solved-warning-mysql_fetch_array-error-please-help/#findComment-429673 Share on other sites More sharing options...
Driiper Posted January 3, 2008 Author Share Posted January 3, 2008 simoceweb, yes the moderator thing is used. it start at line 41 but i still cant solve the thing, anyone? Quote Link to comment https://forums.phpfreaks.com/topic/84355-solved-warning-mysql_fetch_array-error-please-help/#findComment-429674 Share on other sites More sharing options...
Driiper Posted January 3, 2008 Author Share Posted January 3, 2008 simoceweb, yes the moderator thing is used. it start at line 41 but i still cant solve the thing, anyone? edit: thanks that solved my problem i will now se what went wrong Quote Link to comment https://forums.phpfreaks.com/topic/84355-solved-warning-mysql_fetch_array-error-please-help/#findComment-429678 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.