Jump to content

MYSQL_Fetch Error


Monk3h

Recommended Posts

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/monk3h/public_html/alog.php on line 16

 

What did i do wrong? :S

 

$lsel = mysql_query("select * from alog where owner=Admin 
order by id desc limit 100");
while ($log = mysql_fetch_array($lsel)) {     // Line 16

Link to comment
https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/
Share on other sites

I'm guessing there's an error in your query.  Try this instead.

 

$lsel = mysql_query("select * from alog where owner=Admin 
order by id desc limit 100");
if($lsel){
while ($log = mysql_fetch_array($lsel)) {     // Line 16
}
}else{
  die("Unable to connect to database. ".mysql_error());
}

 

This should display the mysql error, or copy your query and put it in phpmyadmin to check for errors.

Link to comment
https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528401
Share on other sites

Parse error: syntax error, unexpected T_STRING in /home/monk3h/public_html/alog.php on line 19

 

 

 

<?php $title = "Admin Log"; include("header.php"); ?>

<?php
if ($stat[rank] != Admin) {
print "You're not an admin.";
include("footer.php");
exit;
}
?>
<img src=images/trash.gif align=right border=0>This is your 
event log. Clear the Log? <a href=log.php?action=clear>Yup</a><br><br>
<table cellspacing=0>
<?php

$lsel = mysql_query("SELECT * FROM  `alog` WHERE `owner` = 'Admin' ORDER BY `id` DESC LIMIT 100");
if($lsel){
while ($log = mysql_fetch_array($lsel)) {
}
}else{
  die("Unable to connect to database. ".mysql_error());
}

print "<tr 
onmouseover=\"this.style.backgroundColor='EDD5AB';\" 
onmouseout=\"this.style.backgroundColor='';
\"><td>$log[log]<br>";

if ($action == clear) {
print ("Log Cleared!");
} 
?>
</table>

<?php include("footer.php"); ?>

 

 

Thats the entire script so far.

Link to comment
https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528417
Share on other sites

Try taking out the while loop and see if the errors goes away

 

<?php $title = "Admin Log"; include("header.php"); ?>

<?php
if ($stat[rank] != Admin) {
print "You're not an admin.";
include("footer.php");
exit;
}
?>
<img src=images/trash.gif align=right border=0>This is your 
event log. Clear the Log? <a href=log.php?action=clear>Yup</a><br><br>
<table cellspacing=0>
<?php

$lsel = mysql_query("SELECT * FROM  `alog` WHERE `owner` = 'Admin' ORDER BY `id` DESC LIMIT 100");
if($lsel){
  echo "query success";
}else{
  die("Unable to connect to database. ".mysql_error());
}

print "<tr 
onmouseover=\"this.style.backgroundColor='EDD5AB';\" 
onmouseout=\"this.style.backgroundColor='';
\"><td>$log[log]<br>";

if ($action == clear) {
print ("Log Cleared!");
} 
?>
</table>

<?php include("footer.php"); ?>

Link to comment
https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528429
Share on other sites

Now you can use the data

 

<?php $title = "Admin Log"; include("header.php"); ?>

<?php
if ($stat[rank] != Admin) {
print "You're not an admin.";
include("footer.php");
exit;
}
?>
<img src=images/trash.gif align=right border=0>This is your 
event log. Clear the Log? <a href=log.php?action=clear>Yup</a><br><br>
<table cellspacing=0>
<?php

$lsel = mysql_query("SELECT * FROM  `alog` WHERE `owner` = 'Admin' ORDER BY `id` DESC LIMIT 100");
if($lsel){
  while($arr = mysql_fetch_assoc($lsel)){
       extract($arr);
       echo "Any arr variables that now have been established via the extract method on the line above";
   }
}else{
  die("Unable to connect to database. ".mysql_error());
}

print "<tr 
onmouseover=\"this.style.backgroundColor='EDD5AB';\" 
onmouseout=\"this.style.backgroundColor='';
\"><td>$log[log]<br>";

if ($action == clear) {
print ("Log Cleared!");
} 
?>
</table>

<?php include("footer.php"); ?>

Link to comment
https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528452
Share on other sites

Look at the code, in the line above the echo statement I have extract($arr);  which creates a variable of all values from the query on a per row basis.  So for example, if your query returns a field called "name" and you wanted to echo it you would simple echo $name because the extract($arr) created a variable for each extracted field.

Link to comment
https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528457
Share on other sites

then this should do the trick:

 

<?php $title = "Admin Log"; include("header.php"); ?>

<?php
if ($stat[rank] != Admin) {
print "You're not an admin.";
include("footer.php");
exit;
}
?>
<img src=images/trash.gif align=right border=0>This is your 
event log. Clear the Log? <a href=log.php?action=clear>Yup</a><br><br>
<table cellspacing=0>
<?php

$lsel = mysql_query("SELECT * FROM  `alog` WHERE `owner` = 'Admin' ORDER BY `id` DESC LIMIT 100");
if($lsel){
  while($arr = mysql_fetch_assoc($lsel)){
       extract($arr);
       echo "$id $owner $log $unread <br />";
   }
}else{
  die("Unable to connect to database. ".mysql_error());
}

print "<tr 
onmouseover=\"this.style.backgroundColor='EDD5AB';\" 
onmouseout=\"this.style.backgroundColor='';
\"><td>$log[log]<br>";

if ($action == clear) {
print ("Log Cleared!");
} 
?>
</table>

<?php include("footer.php"); ?>

 

And then just do whatever you want with the data

Link to comment
https://forums.phpfreaks.com/topic/103155-mysql_fetch-error/#findComment-528483
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.