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
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
Share on other sites

MySQL said: 

 

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$lsel = mysql_query("select * from alog where owner=Admin

order by id desc lim' at line 1

Link to comment
Share on other sites

Try this:

 

$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());
}

Link to comment
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
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
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
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
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
Share on other sites

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.