Help with errors please

Hi everyone…please help me…:frowning: I am trying to follow Mayank’s PHP gallery tutorial from Sitepoint. http://articles.sitepoint.com/article/php-gallery-system-minutes . Thanks to Spike Z and Spence _noodle I was able to get a working code. I am able to upload pictures and view them but they show up with some errors. The errors are
Notice: Undefined variable: category_name in C:\wamp\www\viewgallery.php on line 94,
Notice: Undefined variable: number_of_photos_in_row in C:\wamp\www\viewgallery.php on line 111,
Notice: Undefined variable: number_of_photos_in_row in C:\wamp\www\viewgallery.php on line 112.

I know I am asking a lot here by asking to look at a long piece of code…any help will be appreciated…thank you.

My code is

<?php
    include("config.inc.php");
 
    // initialization
    $result_array = array();
    $counter = 0;
 
    $cid = isset($_GET['cid']) ? (int)($_GET['cid']) : 0;
    $pid = isset($_GET['pid']) ? (int)($_GET['pid']) : 0; 

    // Category Listing
 
    if( empty($cid) && empty($pid) )
    {
        $number_of_categories_in_row = 4;
 
        $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>\
";
 
        foreach($result_array as $category_link)
        {
            if($counter == $number_of_categories_in_row)
            {   
                $counter = 1;
                $result_final .= "\
</tr>\
<tr>\
";
            }
            else
            $counter++;
 
            $result_final .= "\	<td>".$category_link."</td>\
";
        }
 
        if($counter)
        {
            if($number_of_categories_in_row-$counter)
            $result_final .= "\	<td colspan='".($number_of_categories_in_row-$counter)."'>&nbsp;</td>\
";
 
            $result_final .= "</tr>";
        }
    }
 
// Thumbnail Listing
else if( $cid && empty( $pid ) )
{
  $number_of_thumbs_in_row = 4;
// If current page number, use it 
  // if not, set one! 
  if(!isset($_GET['page'])){ 
      $page = 1; 
  } else { 
      $page = $_GET['page']; 
  } 
// Define the number of results per page 
  $max_results = 12; 

  // Figure out the limit for the query based 
  // on the current page number. 
  $from = (($page * $max_results) - $max_results); 
  $result = mysql_query( "SELECT photo_id,photo_caption,photo_filename FROM gallery_photos WHERE 
photo_category='".addslashes($cid)."' LIMIT $from, $max_results"); 
  $nr = mysql_num_rows( $result );
  if( empty( $nr ) )
  {
   $result_final = "\	<tr><td>No Photos found</td></tr>\
";
  }
  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]."' class='img'/></a>";
   }
   mysql_free_result( $result ); 
   $result_final = "<tr>\
";
"<a href='viewgallery.php?cid=$cid'>$category_name</a></td>\
</tr>\
";

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

   }

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


// Figure out the total number of results in DB: 
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM gallery_photos WHERE photo_category=".addslashes
($cid).""),0); 
// Figure out the total number of pages. Always round up using ceil() 
$total_pages = ceil($total_results / $max_results); 
if ($total_pages >1)
{  // build links if more than one page

// Build Page Number Hyperlinks 
$result_final .=  "<tr><td colspan='".$number_of_thumbs_in_row."' class='tcat'>\
There&nbsp;(".$total_pages.")Pages:&nbsp;"; 

// Build Previous Link 
if($page > 1){ 
    $prev = ($page - 1); 
    $result_final .=  "\
<a href=\\"".$_SERVER['PHP_SELF']."?cid=$cid&page=$prev\\" title='Previous Page'><<</a>"; 
} 
for($i = 1; $i <= $total_pages; $i++){ 
    if(($page) == $i){ 
        $result_final .= "&nbsp;[$i]"; 
        } else { 
            $result_final .=  "\
<a href=\\"".$_SERVER['PHP_SELF']."?cid=$cid&page=$i\\" title='Page ".$i."'>$i</a>"; 
    } 
} 
// Build Next Link 
if($page < $total_pages){ 
    $next = ($page + 1); 
    $result_final .=  "\
<a href=\\"".$_SERVER['PHP_SELF']."?cid=$cid&page=$next\\" title='Next Page'>>></a>"; 
} 
$result_final .=  "\
</td></tr>"; 
}
else
{
$result_final .=  "\
";
}      
   }
  }
}

 // display previous and next links if more than one 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 );     

        //fill pid_array with sorted pids in current category 
        $result = mysql_query( "SELECT photo_id FROM gallery_photos WHERE photo_category='".addslashes($cid)."' ORDER BY photo_id" ); 
        $ct = mysql_num_rows( $result );     
        while ($row = mysql_fetch_array($result)) { 
            $pid_array[] = $row[0]; 
             } 
        mysql_free_result( $result ); 

        if( empty($nr ) ) 
        { 
            $result_final = "\	<tr><td>No Photo found</td></tr>\
"; 
        } 
        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>\
\	<td> 
                        <a href=viewgallery.php><font size=4>Albums</font></a> >> 
                        <a href=viewgallery.php?cid=$cid><font size=4>$category_name</font></a><br><br></td>\
</tr>\
"; 
             
            // display previous and next links if more than one photo 
            if ($ct > 1) { 
                  $key = array_search($pid, $pid_array); 
                  $prev = $key - 1; 
                  if ($prev < 0) $prev = $ct - 1; 
                  $next = $key + 1; 
                  if ($next == $ct) $next = 0; 
                  $result_final .= "<tr><td colspan='10'><center>"; 
                  $result_final .= "<a href=viewgallery.php?cid=$cid&pid=".$pid_array[$prev]."><img src=images/prevlabel.gif  border=0 ></a>&nbsp;&nbsp;&nbsp;"; 
                 $result_final .= "(".($key+1)." / ".$ct.")&nbsp;&nbsp;&nbsp;"; 
                  $result_final .= "<a href=viewgallery.php?cid=$cid&pid=".$pid_array[$next]."><img src=images/nextlabel.gif  border=0 ></a>"; 
                 $result_final .= "</center></td></tr>"; 
            }    		

            }
	
	                $result_final .= "<tr>\
\	<td align='center' bordercolor=blue border=1> 
                    <a href=viewgallery.php?cid=$cid&pid=".$pid_array[$next]."><img src='".$images_dir."/".$photo_filename."' border='0' alt='".$photo_caption."' class='img'/></a> 
                    <br /> 
                    $photo_caption 
                    </td> 
                   
					<tr><td><font color=#ffffff></font></td></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 = "\	<tr><td>No Photo found</td></tr>\
";
        }
        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>\
\	<td>
                        <a href='viewgallery.php'>Categories</a> >
                        <a href='viewgallery.php?cid=$cid'>$category_name</a></td>\
</tr>\
";
 
            $result_final .= "<tr>\
\	<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;
?>

You guys ROCK!!! Wow!! that did it…all the errors are gone…!!! Thank you thank you thank you!!! :afro::weee::smashy:

Either removed the dot “.” on this line $result_final .= "<tr>
\ <td> " or look for the section where it has the original variable prior concatenation.

Basically…it show’s you an error because “$result_final .=‘im_contatenated_string’” is parse yet the main “$result_final=‘my_main_string’” wasn’t seen.

SpikeZ…

After spending couple of hours trying to figure out what is happening here the gallery works with out the errors mentioned before. I have two questions if you don’t mind…

  1. When you said drop that in after the two lines you have given, should I drop in , both query after each line?

  2. I have a new error… and just one… and it happens when the large pic is viewed.

Notice: Undefined variable: result_final in C:\wamp\www\viewgallery.php on line 369

And my line 365 - 369 is

          $result_final .= "<tr>\
\	<td> 

                        <a href=viewgallery.php><font size=4>Albums</font></a> >> 

                        <a href=viewgallery.php?cid=$cid><font size=4>$category_name</font></a><br><br></td>\
</tr>\
"; 

Thank you for the help so far… I cannot believe you have helped me to come so far… thank you thank you!

if you think about what you are trying to achieve it is the same as if you click a picture thumbnail from the category and so you are trying to create the url:

viewgallery.php?cid=1&pid=7

which has the category id and the photo id.

You have already selected those fields in the search query so all you need to do is to change the <a href target to reflect the link above.

This is as simple as:


<a href="viewgallery.php?cid='. $rows['photo_category']. '&pid='.$rows['photo_id'].'" />

I am totally blown away by your helpfulness! You wrote the whole thing to help me is just so nice of you! Thank you very much Spike Z…the detailed explanation really help. :slight_smile:

I have a question… I tried to make the thumbnails in the search results click-able…and it works …but it doesn’t lead me to the corresponding picture. I tried to do the code like the viewgallery.php’s thumbnails listing section but I cannot make working links to the images from the search result thumbnail. How do we do this…?

Thanks again Spike Z… I am so thankful for your help… not sure how to thank you really! :slight_smile:

Spike Z… I would have never thought of this… :slight_smile:

If this is not gonna be considered as ‘too many’ th question… let me ask you… is it possible to click on the thumbnail and it will lead us to the larger image view of viewgallery.php? That is with links on the top to categories, next and prev arrows and caption on the bottom (rather than the result here where it takes us to a separate page with no links?

I hope I am not driving you nuts… :slight_smile:

Hi Rajeev.
A search engine is not difficult to achieve and that tutorial is way to over the top for what you need.

You have 1 table that you would search through - gallery_photos. within that table there is only one field you logically need to search - the photo_caption.

Follow the next part carefully!
Here is all the code you need, I will explain a little at the bottom.

ALL ON ONE PAGE!


<?php

include('config.inc.php');

if(isset($_GET['form_id:search'])) {
    
    $images_dir = 'photos';
    
    $q = $_GET['q'];
    
    $sql = mysql_query("
            SELECT
                  photo_id
                , photo_filename
                , photo_caption
                , photo_category
            FROM
                gallery_photos
            WHERE
                photo_caption like '&#37;". mysql_real_escape_string($q) ."%'
        ");
        
        $num_rows = mysql_num_rows($sql);
       
        if($num_rows > 0) {
            
            $results = "<h2>Search Results</h2>
                <p>your search for <span class='searchText'>$q</span> returned $num_rows results
                
                <table>
                    <thead>
                        <tr>
                            <th>Photo</th>
                            <th>Caption</th>
                            <th>Category</th>
                       </tr>
                    </thead>";
         
         
            while($rows = mysql_fetch_assoc($sql)) {
                $results .= "
                <tr>
                    <td><img src=".$images_dir. "/tb_".$rows['photo_filename']." /></td>
                    <td>". $rows['photo_caption'] ."</td>
                    <td>". $rows['photo_category'] ."</td>
                </tr> 
                ";
            }     
                $results .= "</table>";                
        } else {
            
            $results = "<h3>Sorry, no results for <span class='searchText'>$q</span> were found";
        }
     
    
    
    
    
}

?>
<style>
table {
    width: 50%;
}
th {
    background: #e7e7e7;
    font-weight: bold;
}
.searchText {
    font-weight: bold;
    font-style: italic;
}

</style>
<form name="searchform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
<p><label for="q">Search:</label>
    <input type="text" name="q" />
    | 
    <input type="submit" name="Submit" value="Search" /></p>
    <input type="hidden" name="form_id:search" value="1" />
</form>
<hr />
<?php if(isset($_GET['form_id:search'])) { 
    
    echo $results;
}    
?>

So breaking that down a little.

  1. The form that is displayed on the page:

<form name="searchform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
<p><label for="q">Search:</label>
    <input type="text" name="q" />
    | 
    <input type="submit" name="Submit" value="Search" /></p>
    <input type="hidden" name="form_id:search" value="1" />
</form>

A basic form using the GET method rather than post to send the data.


echo $_SERVER['PHP_SELF'];

Tells the form to submit to THIS page


<input type="hidden" name="form_id:search" value="1" />

Hidden field to look for after the form is submitted.
(Personal preference this, other people look for the submit button.)

The PHP bits


if(isset($_GET['form_id:search'])) {

Check if the form has been submitted - if it has, process the next part


    
    $images_dir = 'photos';
    
    $q = $_GET['q'];
    
 

Set a path to the image folder

Set a basic variable to the search string SENT FROM THE FORM./

The query


SELECT
      photo_id
    , photo_filename
    , photo_caption
    , photo_category
FROM
    gallery_photos
WHERE
    photo_caption like '%". mysql_real_escape_string($q) ."%'
 

Select all the fields we need from the gallery_photos table where the photo_caption field contains a work LIKE the search phrase.
Use mysql_real_escape_string to strip nasties and suspicious/malicious code out.


  $num_rows = mysql_num_rows($sql);
 

Are there any results?!

If there are then build up a table using the while loop to run through the results from the query:


  if($num_rows > 0) {
            
            $results = "<h2>Search Results</h2>
                <p>your search for <span class='searchText'>$q</span> returned $num_rows results
                
                <table>
                    <thead>
                        <tr>
                            <th>Photo</th>
                            <th>Caption</th>
                            <th>Category</th>
                       </tr>
                    </thead>";
         
         
            while($rows = mysql_fetch_assoc($sql)) {
                $results .= "
                <tr>
                    <td><img src=".$images_dir. "/tb_".$rows['photo_filename']." /></td>
                    <td>". $rows['photo_caption'] ."</td>
                    <td>". $rows['photo_category'] ."</td>
                </tr> 
                ";
            }     
                $results .= "</table>";                
        }
  

if there are no results, $results should give a basic ‘No results’ message


else {
            
            $results = "<h3>Sorry, no results for <span class='searchText'>$q</span> were found";
        }

Have a good look through the code and play around with it.
Its fairly basic and easy to understand - if you have any questions just ask!

Okay I understand this a bit better now…your code works!

But to get a level deeper in to this … what complications happens when you keep it all in one file? If this is not gonna take too much time … can you briefly explain this…? :slight_smile:

Thanks again Spike Z

Yes!

Yes, it can all be done on one page but that leads to other complications!
Basically preupload.php has the form - when submitted it gets sent to upload.php for processing. Keeps everything neat, tidy and organised :slight_smile:

Can you do…
var_dump($photos_uploaded);

or

var_dump($_FILES);

after below line…
$photos_uploaded = $_FILES[‘photo_filename’];

“I think I didn’t understand the purpose of upload.php file…” rejeev, hopefully you don’t just copy/paste codes from sites verbatim…lol. c",)

So Spike Z I was worrying for nothing? :slight_smile: I think I didn’t understand the purpose of upload.php file… what is the purpose of the upload.php file? Does it enable the uploading images process? Thank you Spike Z…

put this code in at the top of the upload.php page


include("config.inc.php");
if(!$_POST) {
    header("Location: preupload.php");
    exit();
}

that checks if a form has been submitted - if not it redirects you to the preupload page

This error was shown when I generate upload.php not preupload.php…

if you navigate directly to upload.php then it will give you those errors because the form hasn’t been submitted!!

upload.php processes the ‘POSTed’ form data, if you dont post the form then you dont have the data - hence the undefined index error messages!

Yes…var_dump(), as the function itself, dumps the variable content. In your code the error points to $_FILES which came from preupload.php which should contains those 3 associative index; photo_filename, photo_caption and photo_filename.

Notice: Undefined index error means it cannot find those values…i’m checking your codes now.

Hope I am not confusing you… because I usually do that :slight_smile: When you said ‘Below file has the same codes of preupload.php? can you check the actual generated file?
C:\wamp\www\TMPxt4cd7jiol.php’

This error was shown when I generate upload.php not preupload.php…

Looks like preupload.php and upload.php are supposed to be connected. The upload.php shows the error and the generated page shows
<br />
<b>Notice</b>: Undefined index: photo_filename in <b>C:\wamp\www\TMPozpkj7khwv.php</b> on line <b>27</b><br />
<br />
<b>Notice</b>: Undefined index: photo_caption in <b>C:\wamp\www\TMPozpkj7khwv.php</b> on line <b>31</b><br />
<br />

<b>Notice</b>: Undefined index: photo_filename in <b>C:\wamp\www\TMPozpkj7khwv.php</b> on line <b>33</b><br />
<br />
<b>Notice</b>: Undefined index: photo_filename in <b>C:\wamp\www\TMPozpkj7khwv.php</b> on line <b>33</b><br />
<html>
<head>
<title>Photos uploaded</title>
</head>
<body></body>
</html>

preupload.php works fine and this shows this generated html

<html>
<head>
<title> Rajeev lets upload photos!! </title>
</head>
<body>
<form enctype=“multipart/form-data”
action=“upload.php” method=“post”
name=“upload_form”>
<table width=“90%” border=“0”
align=“center” style=“width: 90%;”>
<tr><td>
Select Category
<select name=“category”>
<option value=“1”>Abstract</option>

<option value=“2”>Colorado</option>
<option value=“3”>Gog</option>

 &lt;/select&gt;

</td></tr>
<!—Insert the image fields here –>
<tr><td>
Photo 1:
<input name=“photo_filename
type=“file” />
</td></tr>

<tr><td>
Caption:
<textarea name=“photo_caption” cols=“50”
rows=“3”></textarea>
</td></tr><tr><td>
Photo 2:
<input name=“photo_filename
type=“file” />
</td></tr>
<tr><td>
Caption:
<textarea name=“photo_caption” cols=“50”
rows=“3”></textarea>
</td></tr><tr><td>
Photo 3:
<input name=“photo_filename
type=“file” />

</td></tr>
<tr><td>
Caption:
<textarea name=“photo_caption” cols=“50”
rows=“3”></textarea>
</td></tr><tr><td>
Photo 4:
<input name=“photo_filename
type=“file” />
</td></tr>
<tr><td>
Caption:
<textarea name=“photo_caption” cols=“50”
rows=“3”></textarea>
</td></tr><tr><td>

Photo 5:
<input name=“photo_filename
type=“file” />
</td></tr>
<tr><td>
Caption:
<textarea name=“photo_caption” cols=“50”
rows=“3”></textarea>
</td></tr><tr><td>
Photo 6:
<input name=“photo_filename
type=“file” />
</td></tr>
<tr><td>
Caption:
<textarea name=“photo_caption” cols=“50”
rows=“3”></textarea>

</td></tr><tr><td>
Photo 7:
<input name=“photo_filename
type=“file” />
</td></tr>
<tr><td>
Caption:
<textarea name=“photo_caption” cols=“50”
rows=“3”></textarea>
</td></tr><tr><td>
Photo 8:
<input name=“photo_filename
type=“file” />
</td></tr>
<tr><td>
Caption:
<textarea name=“photo_caption” cols=“50”
rows=“3”></textarea>

</td></tr><tr><td>
Photo 9:
<input name=“photo_filename
type=“file” />
</td></tr>
<tr><td>
Caption:
<textarea name=“photo_caption” cols=“50”
rows=“3”></textarea>
</td></tr>
<tr><td>
<input type=“submit” name=“submit”
value=“Add Photos” />
</td></tr>

</table>
</form>
</body>
</html>

Thank you for continuing to help me modtup…you are the best…:slight_smile:

Guys…:slight_smile: Do I ever stop asking questions you wonder eh? Gallery is still working… I love it. When I am done with it I will email the links. Here is a link to my photography page. I don’t post there anymore but you can see some of my images. http://photo.net/photodb/member-photos?user_id=637595&include=all&unlimit=1

But I have a question… when I publish the upload.php I get two errors.

Notice: Undefined index: photo_filename in C:\wamp\www\TMPvggvd7jfmw.php on line 27

Notice: Undefined index: photo_caption in C:\wamp\www\TMPvggvd7jfmw.php on line 30

And here is the upload.php code

&lt;?php
	include("config.inc.php");

	// initialization
	$result_final = "";
	$counter = 0;

	// List of our known photo types
	$known_photo_types = array( 
						'image/pjpeg' =&gt; 'jpg',
						'image/jpeg' =&gt; 'jpg',
						'image/gif' =&gt; 'gif',
						'image/bmp' =&gt; 'bmp',
						'image/x-png' =&gt; 'png'
					);
	
	// GD Function List
	$gd_function_suffix = array( 
						'image/pjpeg' =&gt; 'JPEG',
						'image/jpeg' =&gt; 'JPEG',
						'image/gif' =&gt; 'GIF',
						'image/bmp' =&gt; 'WBMP',
						'image/x-png' =&gt; 'PNG'
					);

	// Fetch the photo array sent by preupload.php
	$photos_uploaded = $_FILES['photo_filename'];

	// Fetch the photo caption array
	$photo_caption = $_POST['photo_caption'];

	while( $counter &lt;= count($photos_uploaded) )
	{
		if($photos_uploaded['size'][$counter] &gt; 0)
		{
			if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types))
			{
				$result_final .= "File ".($counter+1)." is not a photo&lt;br /&gt;";
			}
			else
			{
				mysql_query( "INSERT INTO gallery_photos(`photo_filename`, `photo_caption`, `photo_category`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."')" );
				$new_id = mysql_insert_id();
				$filetype = $photos_uploaded['type'][$counter];
				$extention = $known_photo_types[$filetype];
				$filename = $new_id.".".$extention;

				mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );

				// Store the orignal file
				copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$filename);

				// Let's get the Thumbnail size
				$size = GetImageSize( $images_dir."/".$filename );
				if($size[0] &gt; $size[1])
				{
					$thumbnail_width = 100;
					$thumbnail_height = (int)(100 * $size[1] / $size[0]);
				}
				else
				{
					$thumbnail_width = (int)(100 * $size[0] / $size[1]);
					$thumbnail_height = 100;
				}
			
				// Build Thumbnail with GD 1.x.x, you can use the other described methods too
				$function_suffix = $gd_function_suffix[$filetype];
				$function_to_read = "ImageCreateFrom".$function_suffix;
				$function_to_write = "Image".$function_suffix;

				// Read the source file
				$source_handle = $function_to_read ( $images_dir."/".$filename ); 
				
				if($source_handle)
				{
					// Let's create an blank image for the thumbnail
				     	$destination_handle = ImageCreate ( $thumbnail_width, $thumbnail_height );
				
					// Now we resize it
			      	ImageCopyResized( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1] );
				}

				// Let's save the thumbnail
				$function_to_write( $destination_handle, $images_dir."/tb_".$filename );
				ImageDestroy($destination_handle );
				//

				$result_final .= "&lt;img src='".$images_dir. "/tb_".$filename."' /&gt; File ".($counter+1)." Added&lt;br /&gt;";
			}
		}
	$counter++;
	}

	// Print Result
echo &lt;&lt;&lt;__HTML_END

&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;Photos uploaded&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
	$result_final
&lt;/body&gt;
&lt;/html&gt;

__HTML_END;
?&gt;

I see that ‘photo_filename’ and ‘photo_caption’ are not defined in the file. How do I do this? Do use ‘include’ to bring in the entire ‘preupload.php’ ?

I am a bit confused here…because I use the preupload.php to upload the images and it works. So what is the purpose of upload.php?

Thank you guys… anything you can tell will help :slight_smile:

Good to see you are still trying Rajeev!

The code is almost right,


echo '<pre>';
print_r($row);
echo '</pre>';  

Note the $row variable is the array that holds the results from the database query.
You would need to add this code AFTER you have run the SQL and assigned $row = mysql_fetch_assoc($sql);

BUT…
You cant in this particular instance as you are using the $row = mysql_fetch_assoc($sql); code in the while loop - once it has been used it cant be reused in the same format.

print_r() is a very useful debugging tool and one you should familiarise yourself with.

What Spence means is to create your images and put them all into the same folder. Each image would be named to be the same as the category_id that is being pulled from the database - and so unique.

So if you had 4 categories:
MyFirstCategory with the category_id of 101 you would create an image called categoryImage101.jpg
MySecondCategory with the category_id of 102 you would create an image called categoryImage102.jpg
MyThirdCategory with the category_id of 101 you would create an image called categoryImage103.jpg
MyFourthCategory with the category_id of 102 you would create an image called categoryImage104.jpg

They would all be in the same folder /photos/images/

Then when you write the code, all you do is append the $row[0] variable - (remember that $row[0] is the category_id field in the database)


$result_array[] = "<a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a><img src='/photos/images/categoryImage".$row[0].".jpg' border=0 height='50px' width='50px' />"; 

See how you get on with that and post back if you need more help

GUYS… you helped me to reach where I wanted the gallery to be. It is a fully functional gallery!!! :smiley: :rofl: I am so happy …I don’t even know what to type here! But GUYS!! thank you so much… it is so cool that people like you are out there helping others who you never have even seen and it REALLY does make a difference in people’s life!! . I am a photographer so if I can make anything related to code work WITH HELP that is a miracle! I am that slow! :smiley: Spike Z , Spence, Modtup…you guys made me understand PHP a little better. I used to look at it and go ‘:eek::eek:’ now at least I know what is an array!! :smiley: Is there any place on web or books out there you recommend that I can use to start PHP from the very beginning? Thanks again guys!!! :nanaman::nanaman: