...

View Full Version : Need help with PHP log



Sing
02-28-2010, 10:46 PM
Hey! Well, I have a code for adding contant to a site through a PHP system, but my system logs are showing up as:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a1198938/public_html/tv/logs.php on line 15


Here is the /tv/logs.php file:

<h2>Logs</h2><br>
<?php
if ($logged[rank] == "3"){
$color1 = "greyBox";
$color2 = "whiteBox";
$row_count = 0;
?>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="80%" class="darkgreyBox" align="left"><b>Activity</b></td>
<td width="20%" class="darkgreyBox" align="center"><b>date</b></td>
</tr>
<?php
$getlog = mysql_query("SELECT * FROM `logs` ORDER BY `id` DESC");
while($row = mysql_fetch_array($getlog)) {
$row_color = ($row_count % 2) ? $color1 : $color2;
?>
<tr>
<td width="80%" align="left"><div class="<?php echo $row_color; ?>"><?php echo $row['log']; ?></div></td>
<td width="20%" align="center"><div class="<?php echo $row_color; ?>"><?php echo $row['date']; ?></div></td>
</tr>
<?php
$row_count++;
}
?>
</table>
<?php
}else{
?>
You don't have permission to view this page
<?php
}
?>
If you require more info, please let me know. I will very much appreciate the answer :)

bdl
02-28-2010, 11:12 PM
Where is your MySQL connection code?



// mysql_connect()
// mysql_select_db()
$getlog = mysql_query("SELECT * FROM `logs` ORDER BY `id` DESC");
while($row = mysql_fetch_array($getlog)) {

Ndogg
02-28-2010, 11:15 PM
Try:

while($row = mysql_fetch_assoc($getlog))

bdl
02-28-2010, 11:16 PM
@Ndogg> That's the exact same thing in this context.

Ndogg
02-28-2010, 11:37 PM
Ohh, I though array and assoc did different things.

bdl
02-28-2010, 11:44 PM
Ohh, I though array and assoc did different things.

You're right, they do. _assoc() (http://www.php.net/mysql_fetch_assoc) returns an associative mapped array, array keys that have an actual value, e.g. $row['fieldname'].

_array() (http://www.php.net/mysql_fetch_array) returns both a numerically indexed array and an associative indexed array. In most cases it is wise to simply use the _assoc method so as to not tie up resources with the extraneous indexes that are unused.

However, in this context, with this error code, it doesn't matter which is used. It is my hunch we're missing the actual db connection or the database selection here, thus the fetch command is failing because $getlog is an invalid resource handler. OTOH, the SQL statement itself could be invalid, but it looks pretty innocuous.

Sing
03-01-2010, 12:02 AM
Where is your MySQL connection code?



// mysql_connect()
// mysql_select_db()
$getlog = mysql_query("SELECT * FROM `logs` ORDER BY `id` DESC");
while($row = mysql_fetch_array($getlog)) {


Sorry, I'm not that PHP savy - explain?? But I do know that this script has a config.php file in it connecting it to my MySQL

Sing
03-03-2010, 04:48 AM
I figured it out - there was nothing in my MySQL logging :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum