SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    autmoated gallery script (viewgallery.php undefined index)

    Im trying to work with the automated gallery script that sitepoint featured, it seems to work decently except when Im using the viewgallery.php- I don't know how to fix these errors- any suggestions?

    Notice: Undefined index: cid in C:\(directory location name)\pictures\viewgallery.php on line 8

    Notice: Undefined index: pid in C:\(directory location name)\pictures\viewgallery.php on line 9


    picture table1 (0)
    picture table2 (4)

    viewgallery.php::

    <?php
    include("config.inc.php");

    // initialization
    $result_array = array();
    $counter = 0;

    $cid = (int)($_GET['cid']);
    $pid = (int)($_GET['pid']);

    // Category Listing

    if( empty($cid) && empty($pid) )
    {
    $number_of_categories_in_row = 2;

    $result = mysql_query( "SELECT c.category_id,c.category_name,COUNT(photo_id)
    FROM gallery_category as c
    LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
    GROUP BY c.category_id" );
    while( $row = mysql_fetch_array( $result ) )
    {
    $result_array[] = "<a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")";
    }
    mysql_free_result( $result );

    $result_final = "<tr>\n";

    foreach($result_array as $category_link)
    {
    if($counter == $number_of_categories_in_row)
    {
    $counter = 1;
    $result_final .= "\n</tr>\n<tr>\n";
    }
    else
    $counter++;

    $result_final .= "\t<td>".$category_link."</td>\n";
    }

    if($counter)
    {
    if($number_of_categories_in_row-$counter)
    $result_final .= "\t<td colspan='".($number_of_categories_in_row-$counter)."'>&nbsp;</td>\n";

    $result_final .= "</tr>";
    }
    }


    // Thumbnail Listing

    else if( $cid && empty( $pid ) )
    {
    $number_of_thumbs_in_row = 5;

    $result = mysql_query( "SELECT photo_id,photo_caption,photo_filename FROM gallery_photos WHERE photo_category='".addslashes($cid)."'" );
    $nr = mysql_num_rows( $result );

    if( empty( $nr ) )
    {
    $result_final = "\t<tr><td>No Category found</td></tr>\n";
    }
    else
    {
    while( $row = mysql_fetch_array( $result ) )
    {
    $result_array[] = "<a href='viewgallery.php?cid=$cid&pid=".$row[0]."'><img src='".$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."' /></a>";
    }
    mysql_free_result( $result );

    $result_final = "<tr>\n";

    foreach($result_array as $thumbnail_link)
    {
    if($counter == $number_of_thumbs_in_row)
    {
    $counter = 1;
    $result_final .= "\n</tr>\n<tr>\n";
    }
    else
    $counter++;

    $result_final .= "\t<td>".$thumbnail_link."</td>\n";
    }

    if($counter)
    {
    if($number_of_photos_in_row-$counter)
    $result_final .= "\t<td colspan='".($number_of_photos_in_row-$counter)."'>&nbsp;</td>\n";

    $result_final .= "</tr>";
    }
    }
    }

    // Full Size View of Photo
    else if( $pid )
    {
    $result = mysql_query( "SELECT photo_caption,photo_filename FROM gallery_photos WHERE photo_id='".addslashes($pid)."'" );
    list($photo_caption, $photo_filename) = mysql_fetch_array( $result );
    $nr = mysql_num_rows( $result );
    mysql_free_result( $result );

    if( empty( $nr ) )
    {
    $result_final = "\t<tr><td>No Photo found</td></tr>\n";
    }
    else
    {
    $result = mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes($cid)."'" );
    list($category_name) = mysql_fetch_array( $result );
    mysql_free_result( $result );

    $result_final .= "<tr>\n\t<td>
    <a href='viewgallery.php'>Categories</a> &gt;
    <a href='viewgallery.php?cid=$cid'>$category_name</a></td>\n</tr>\n";

    $result_final .= "<tr>\n\t<td align='center'>
    <br />
    <img src='".$images_dir."/".$photo_filename."' border='0' alt='".$photo_caption."' />
    <br />
    $photo_caption
    </td>
    </tr>";
    }
    }

    // Final Output
    echo <<<__HTML_END

    <html>
    <head>
    <title>Gallery View</title>
    </head>
    <body>
    <table width='100%' border='0' align='center' style='width: 100%;'>
    $result_final
    </table>
    </body>
    </html>

    __HTML_END;
    ?>

  2. #2
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    one other thing...

    I included the viewgallery.php into an existing page (pictures.php) when I click on a link to bring me to the pictures that I uploaded it brings me back to viewgallery.php
    How do I keep the links and pictures within my original page (pictures.php) I'd like the photos that I uploaded to show up within the space I created and possibly to do a slideshow type of thing as well.


    any suggestions on how to accomplish this?

  3. #3
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any ideas on how to do these?

  4. #4
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    add this to the top of the script:

    PHP Code:
    error_reporting(E_ALL & ~E_NOTICE); 
    To suppress the notices issued. Or you can fix the code so it doesn't issue the notices, either way .
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  5. #5
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well- I would like to not have the errors at all, which means that hiding them is not an option. Hence why I asked for help regarding them.

    I just dont understand how to do these fixes. I cant find anything wrong and I used the pages that came from the actual article on the gallery script.


    but thank you for that quick code to hide the notices

  6. #6
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The notices are issued because a variable was checked that doesn't exist. You need to use isset() to check that a variable actually exists before checking it.

    No error:
    PHP Code:
    <?php 
     $a 
    false;
     if (!
    $a)
         echo 
    '$a is false';
     
    ?>
    Issues a notice:
    PHP Code:
    <?php
     
    if (!$a)
         echo 
    '$a is false';
     
    ?>
    Why does it issue a notice? Because $a was never defined.

    The same thing happens with array keys that do not exist.

    For example, let's say the user goes to script.php, which contains the following:
    PHP Code:
    if ($_GET['page'])
         echo 
    '$_GET[page] set'
    If they enter script.php?page=test there is no problem, but if they just go to script.php, then there is a notice issued.

    Another time notices are issued is when not quoting a string:
    PHP Code:
    $message Hello
    PHP checks for a constant named "Hello" and doesn't find one, so it assigns $message the string "Hello", but it issues a notice. The same thing occurs with array keys, etc.

    PHP Code:
    $a = array();
     
    $a[key] = 1
    Issues a notice, while the following is correct:

    PHP Code:
    $a = array();
     
    $a['key'] = 1

    Hope that helps.

    Most available scripts are NOT written to comply with E_ALL error_reporting in PHP, code is sloppy.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.


Bookmarks

Posting Permissions

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