Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    61
    Thanks
    2
    Thanked 1 Time in 1 Post

    Question Need help with PHP log

    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:
    PHP Code:
                        <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

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Where is your MySQL connection code?

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

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts
    Try:

    while($row = mysql_fetch_assoc($getlog))

  • #4
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    @Ndogg> That's the exact same thing in this context.

  • #5
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts
    Ohh, I though array and assoc did different things.

  • #6
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by Ndogg View Post
    Ohh, I though array and assoc did different things.
    You're right, they do. _assoc() returns an associative mapped array, array keys that have an actual value, e.g. $row['fieldname'].

    _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.

  • #7
    New Coder
    Join Date
    Oct 2009
    Posts
    61
    Thanks
    2
    Thanked 1 Time in 1 Post
    Quote Originally Posted by bdl View Post
    Where is your MySQL connection code?

    PHP 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

  • #8
    New Coder
    Join Date
    Oct 2009
    Posts
    61
    Thanks
    2
    Thanked 1 Time in 1 Post
    I figured it out - there was nothing in my MySQL logging


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •