Use of undefined constant - please help

Discussion in 'PHP' started by PoderOdunk, Oct 25, 2007.

  1. #1
    I'm getting the following errors: I get the same thing with other lines in this function, but don't see anything wrong with it or different than my other functions.

    PHP Notice: Use of undefined constant gamedesc - assumed 'gamedesc' in functions.php on line 1554

    Here is line 1554 of functions.php

    $featuredgamedesc2 = $row[gamedesc];

    Which is part of this whole function:

    // This fuction displays the featured games on the arcade
    function featured_game_frame($rewrite,$base_url,$sedir)
    {
    // Determine the featured games sorting by random
    $x = 0;
    $sql_query = "SELECT * from games WHERE featured = 1 ORDER by rand() LIMIT 8";
    //store the SQL query in the result variable
    $result = mysql_query($sql_query);
    if(mysql_num_rows($result))
    {
    //output as long as there are still available fields
    while($row = mysql_fetch_array($result))
    {
    $x++;
    $featuredgametitle = $row[gametitle];
    $featuredgametitle = stripslashes($featuredgametitle);
    $featuredgametitle2 = $row[gametitle];
    $featuredgameicon = $row[gameicon];
    $featuredgamedesc2 = $row[gamedesc];
    $gameid = $row[gameid];
    $title = make_friendly($featuredgametitle);

    if ($rewrite ==0)
    $gamelink = $base_url."index.php?action=playgame&gameid=".$gameid;
    else
    $gamelink = $base_url."addicting-".$sedir."/".$gameid."/".$title;
    if($x == 9)
    $content = $content."</tr><tr valign=\"top\">";
    $content = $content."<td class=\"cellTitles\" width=\"120\"><center><a href=\"$gamelink\" alt=\"$featuredgametitle2\" target=\"_parent\"><img src=\"http://www.bootyarcade.com/games/images/".$featuredgameicon."\" width=\"100\" height=\"100\" alt=\"$featuredgametitle2 - $featuredgamedesc2\" title=\"$featuredgametitle2 - $featuredgamedesc2\" border=\"0\"><br>
    $featuredgametitle</a></center></td>";



    }
    }
    //if no fields exist
    else
    {
    $content = "<i>No games played</i>";
    }

    return $content;
    }
     
    PoderOdunk, Oct 25, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    All $row[gametitle] and similar should be: $row['gametitle'] (note the quotes)

    The array keys have to be enclosed in quotes. I don't understand how programmers are so lazy still to leave them out. :( (No offense to you)
     
    nico_swd, Oct 25, 2007 IP
  3. PoderOdunk

    PoderOdunk Active Member

    Messages:
    267
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #3
    no offense taken and thank you for the help, that fixed it..

    Now I have another error popping in my logs...

    undefined index: trackclicks in config.php line 86 ... here is line 86:

    $trackclicks = $row['trackclicks'];

    Any chance it's a similarly simple fix?
     
    PoderOdunk, Oct 25, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Try:
    
    $trackclicks = isset($row['trackclicks']) ? $row['trackclicks'] : 0;
    
    PHP:
    By the way, your error reporting is not set to the default, because these errors are usually not shown. But it's still better to fix them because if error logging is enabled, it slows down the script's performance. (And it's also better to fix them if error logging is disabled)
     
    nico_swd, Oct 25, 2007 IP
  5. PoderOdunk

    PoderOdunk Active Member

    Messages:
    267
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #5
    nico, pls pm me your paypal so I can thank you in a more meaningful way...

    If you're willing, I have a couple more errors still coming in...

    undefined variable content

    $content = $content."<td class=\"cellTitles\" width=\"120\"><center><a href=\"$gamelink\" alt=\"$featuredgametitle2\" target=\"_parent\"><img src=\"http://www.bootyarcade.com/games/images/".$featuredgameicon."\" width=\"100\" height=\"100\" alt=\"$featuredgametitle2 - $featuredgamedesc2\" title=\"$featuredgametitle2 - $featuredgamedesc2\" border=\"0\"><br>
    $featuredgametitle</a></center></td>";



    }
    }
    //if no fields exist
    else
    {
    $content = "<i>No games played</i>";
    }

    return $content;
    }


    -----------------------------------------------------------

    also got this one...

    PHP Warning: session_start(): Cannot send sessions cache limiter - headers already sent (output started at topf.php:2) in functions.php on line 2

    line 2 of functions.php:

    session_start();

    topf.php includes this code:

    <? include("./includes/functions.php");
    include("./includes/config.php");
    $_SESSION['category_list'] = display_categories($rewrite,$base_url);?>

    I assume it has something to do with the include/functions.php on that page?

    Thanks again and please do pm me your paypal... I sincerely appreciate you helping a stranger!
     
    PoderOdunk, Oct 25, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Above this piece of code, place this:
    
    if (!isset($content))
    {
        $content = '';
    }
    
    PHP:

    Make sure there are no white spaces in front of any <? tags. Trim them all if there are any. In functions.php and config.php too. The <? must be the very first thing in these files.

    
    <?php
    include("./includes/functions.php"); 
    include("./includes/config.php");
    $_SESSION['category_list'] = display_categories($rewrite,$base_url);
    ?>
    
    PHP:

    And don't worry about Paypal... I'm here to help everyone. :)
     
    nico_swd, Oct 25, 2007 IP
  7. PoderOdunk

    PoderOdunk Active Member

    Messages:
    267
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #7
    yay! I'm down to just the last error...

    I don't see any extra spaces before php starts on any page.

    Is there anything else it could be??
     
    PoderOdunk, Oct 25, 2007 IP