Page 1 of 1

PHP Won't load variables correctly

Posted: Thu May 13, 2004 3:45 am
by brett2
Ok, so I have written a script that creates basically two HTML pages. First, it creates a page for thumbnailed images. Then, when a thumbnailed image is clicked, the larger image page is created. The script is set up in this order:

-- Use the $_GET expression to get the variable from the header.
-- Create the thumbnail page
-- Create the large image page
-- Create the check() function
-- Create the switch with variables

Here's the code... all 300 lines of it.

Code: Select all

<?php
$image_num = $_GET['img'];
if($image_num != ""){
        echo_image($title,$image_num,$caption);
}else{
        echo_thumbnail();
}
stop();
################################################################
#                                                              #
#           FUNCTION TO CREATE THE THUMBNAIL PAGE              #
#                                                              #
################################################################

function echo_thumbnail() {
	#########################################################
	#                                                       #
	#    DEFINE VARIABLES TO BE USED WITHIN THE FUNCTION    #
	#                                                       #
	#########################################################
		$num_of_images = '52';
		$title = 'Halloweenfest - 2003: October 31, 2003 - New Jersey';
		$vlink = '#009999';
		$alink = "#0066CC";
		$link = "#006666";
		$text = "#FFFFFF";
		$bgColor = "#006699";
		$month_image_path = './images/thumbs/2003halloweenFest';
		$up_one_level = 'http://userpages.umbc.edu/~brett2/phpimageLoader/imageLoader.php';
		$month_path = './imageLoader?';
	############################################
	#    DONE DEFINING FUNCTIONAL VARIABLES    #
	############################################
	
        echo('<HTML><TITLE>'.$title.'</TITLE>');
        echo('<BODY bgcolor="'.$bgColor.'" " vlink="'.$vlink.'" alink="'.$alink.'" link="'.$link.'">');
        echo('<P align="center"><A href="'.$up_one_level.'"><FONT face="Webdings" color="'.$text.'">l</FONT></A></P>');
        $x = 1;
        echo('<P align="center">');
        for($x =1; $x <= $num_of_images; $x++ ) {
                echo('<A href="'.$month_path.'img='.check($x).'" target="_blank">');
                echo('<IMG border="0" src="'.$month_image_path.check($x).'.jpg"></A>');
                echo('&nbsp;&nbsp;&nbsp;');
                if( $x%5 == 0) {
                        echo('</BR>');
                }
        }
        echo('</P>');
        echo('</BODY>');
        echo('</HTML>');
}

################################################################
#                                                              #
#    FUNCTION TO CREATE THE LARGE IMAGES ON THUMBNAIL CLICK    #
#                                                              #
################################################################

function echo_image($title,$image_num,$caption) {
	#########################################################
	#                                                       #
	#    DEFINE VARIABLES TO BE USED WITHIN THE FUNCTION    #
	#                                                       #
	#########################################################	
		$num_of_images = '52';
		$vlink = '#009999';
		$alink = "#0066CC";
		$link = "#006666";
		$text = "#FFFFFF";
		$bgColor = "#006699";
		$month_image_path = './images/2003halloweenFest';
		$up_one_level = 'http://userpages.umbc.edu/~brett2/phpimageLoader/imageLoader.php';
		$month_path = './imagesLoader.php?';
		$month_home = './imageLoader.php';
	############################################
	#    DONE DEFINING FUNCTIONAL VARIABLES    #
	############################################
		
		echo("<HTML><HEAD><TITLE>".$title."</TITLE>");
        echo('<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>');
        echo('<BODY vLink='.$vlink.' aLink='.$alink.' link='.$link.' bgColor='.$bgColor.'>');
        echo('<P align=center><IMG src="'.$month_image_path.$image_num.'.jpg" border=0></P>');
        echo('<P align=center><br><FONT color='.$text.'>'.$caption.'</FONT></P>');
        echo('<P align=center>');
        if($image_num > 1)
        {
                $img_num_L = $image_num - 1;
                echo('<A href="'.$month_path.'img='.$img_num_L.'">');
                echo('<FONT color='.$llink.'>Backwards</FONT></A>');
        }
        echo(' &nbsp;&nbsp;&nbsp;');
        echo('<A href="'.$month_home.'"><FONT face=Webdings color='.$text.'>l</FONT></FONT></A>');
        echo('&nbsp;&nbsp;&nbsp; ');
        if($image_num < $number_of_images)
        {
                $img_num_U = $image_num + 1;
                echo('<A href="'.$month_path.'img='.$img_num_U.'">');
                echo('<FONT color='.$llink.'>Forwards</FONT></A>');
        }
        echo('</P></BODY></HTML>');
}
###############################################################################
function check($num)
{
        if($num < 10){
                return '0'.$num;
        }
return $num;
}

#######################################################################
#                                                                     #
#    FUNCTION TO DEFINE THE TITLE, AND COMMENT OF THE LARGE IMAGES    #
#                                                                     #
#######################################################################
$img *= 1;
switch($img){
        case 1:
                echo_image("HalloweenFest 2003 - Stage",$img,"I was here");
                break;

        case 2:
                echo_image("HalloweenFest 2003 - The Grounds",$img,"The Grounds as viewed from the stage area");
                break;

        case 3:
                echo_image("HalloweenFest 2003 - Activities",$img,"Blow-Up Activities for the kids");
                break;

        case 4:
                echo_image("HalloweenFest 2003 - Group Shot 1",$img,"The Group... Need I say More?");
                break;

        case 5:
                echo_image("HalloweenFest 2003 - Group Shot 2",$img,"Hmm... A closer shot?  I am surprised the camera did not break");
                break;

        case 6:
                echo_image("HalloweenFest 2003 - Group Shot 3",$img,"Well, we're alive because we are standing.");
                break;

        case 7:
                echo_image("HalloweenFest 2003 - Group Shot 4",$img,"And closer yet again...");
                break;

        case 8:
                echo_image("HalloweenFest 2003 - Hay Bail Pumpkin Dryer",$img,"Boo!!! I see YOU!!!");
                break;

        case 9:
                echo_image("HalloweenFest 2003 - Signs",$img,"Happy Halloween Everybody!!!");
                break;

        case 10:
                echo_image("HalloweenFest 2003 - Halloween Characters",$img,"I see the monster... but who is the guy in the bluish/purple?");
                break;

        case 11:
                echo_image("HalloweenFest 2003 - More Characters",$img,"I Figured it out... He's Frankenstein!!!");
                break;

        case 12:
                echo_image("HalloweenFest 2003 - Pin the Something On The Something",$img,"I wonder who is in the blind-fold....?");
                break;

        case 13:
                echo_image("HalloweenFest 2003 - Pin the Nose on the Pumpkin!!",$img,"Yup... It's me.");
                break;

        case 14:
                echo_image("HalloweenFest 2003 - Pin the Nose on the Pumpkin!!",$img,"Wait that's not me!!");
                break;

        case 15:
                echo_image("HalloweenFest 2003 - Pin the Nose on the Pumpkin!!",$img,"Look at how close she got it!!");
                break;

        case 16:
                echo_image("HalloweenFest 2003 - Tale As Old As Time...",$img,"Beauty and the Beast... but I'm not in the picture");
                break;

        case 17:
                echo_image("HalloweenFest 2003 - Scratch It... Scratch, Scratch It!",$img,"The Beast must have fleas....");
                break;

        case 18:
                echo_image("HalloweenFest 2003 - WTF MATE?!?!?!?!",$img,"I thought this was scary? AHH!! It's a Christmas tree!!!  It's going to Eat ME!!!!");
                break;

        case 19:
                echo_image("HalloweenFest 2003 - WTF MATE?!?!?!?!",$img,"Oh wait... It's just a kid");
                break;
                
        case 20:
                echo_image("HalloweenFest 2003 - It's an Elephant!",$img,"Did it swallow a treasure chest?");
                break;
                
        case 21:
        		echo_image("HalloweenFest 2003 - State Worker in Training",$img,"But Mom... I don't wanna!!");
        		break;
        		
        case 22:
        		echo_image("HalloweenFest 2003 - Harry Potter",$img,"Is this a big enough smile?");
        		break;
        		
        case 23:
        		echo_image("HalloweenFest 2003 - Interesting Costumes",$img,"Need a little help on this one....");
        		break;
        case 24:
        		echo_image("HalloweenFest 2003 - Cinderelly Cinderelly!!",$img,"Where's Gus Gus?");
        		break;
        case 25:
        		echo_image("HalloweenFest 2003 - Lions & Tigers & Bears!!",$img,"If I.  Were King. Of the FORRREST!!");
        		break;
        case 27:
        		echo_image("HalloweenFest 2003 - Some like to go that way -->",$img,"The sum of the square of any hypotenuse....");
        		break;
        case 28:
        		echo_image("HalloweenFest 2003 - Look at the baby!!",$img,"Do you really think the kid is having a good time?");
        		break;
        case 29:
        		echo_image("HalloweenFest 2003 - mmmm.... Earth Meat",$img,"We are from planet Zoird.  We come to smile at you....");
        		break;
        case 30:
        		echo_image("HalloweenFest 2003 - Excuse Me!!",$img,"Where has my broom-stick gone?  I can't fly without the broom-stick!!");
        		break;
        case 31:
        		echo_image("HalloweenFest 2003 - lalalalalala!!",$img,"I don't want to be in the parade.  I'll just stand here!");
        		break;
        case 32:
        		echo_image("HalloweenFest 2003 - Who Lives In a Pineapple Under the sea!!",$img,"Some huge fish guy!!!");
        		break;
        case 33:
        		echo_image("HalloweenFest 2003 - And who would I do?",$img,"Anyone... age 13 and up!!!");
        		break;
        case 34:
        		echo_image("HalloweenFest 2003 - What in the world?!?!?!",$img,"I don't get what she is...");
        		break;
        case 35:
        		echo_image("HalloweenFest 2003 - Back to the beauty",$img,"And there's the BEAST!!!");
        		break;
        case 36:
        		echo_image("HalloweenFest 2003 - I'M FAT!!!",$img,"Boooow oup!!!");
        		break;
        case 37:
        		echo_image("HalloweenFest 2003 - Uh Oh!!!",$img,"My Thong is ridin up on me!!!");
        		break;
        case 38:
        		echo_image("HalloweenFest 2003 - WILMA!!!!",$img,"Let's 'drive' somewhere");
        		break;
        case 39:
        		echo_image("HalloweenFest 2003 - Flinstones....",$img,"Can't this go any faster?");
        		break;
        case 40:
        		echo_image("HalloweenFest 2003 -Here she comes to wreck the day!!!",$img,"I didn't know Elephants were princesses....");
        		break;
        case 41:
        		echo_image("HalloweenFest 2003 - Umm.....",$img,"Perhaps we're looking at the grass... what a great costume.");
        		break;
        case 42:
        		echo_image("HalloweenFest 2003 - ICE CREAM!!!",$img,"With rainbow Jimmies/Sprinkles");
        		break;
        case 43:
        		echo_image("HalloweenFest 2003 - It's BAND TIME!!!",$img,"Ahh the sweet sounds of clowns.");
        		break;
        case 44:
        		echo_image("HalloweenFest 2003 - I'm Macaroni",$img,"But I don't like to eat it");
        		break;
        case 45:
        		echo_image("HalloweenFest 2003 - A Flowering Personality",$img,"Wassup?");
        		break;
        case 46:
        		echo_image("HalloweenFest 2003 - umm.... ok?",$img,"Costumes of deserving noteriety...");
        		break;
        case 47:
        		echo_image("HalloweenFest 2003 - AAAHHHHH!!!!",$img,"It's FUZZY & Up Close!!!!");
        		break;
        case 48:
        		echo_image("HalloweenFest 2003 - I WIN!!",$img,"She got a trophy for something....");
        		break;
        case 49:
        		echo_image("HalloweenFest 2003 - #4 in the line....",$img,"#1 in the Standings");
        		break;
        case 50:
        		echo_image("HalloweenFest 2003 - Another trophy shot",$img,"Where did she go?");
        		break;
        case 51:
        		echo_image("HalloweenFest 2003 - There she is....",$img,"I made her pop out of her box...");
        		break;
        case 52:
        		echo_image("HalloweenFest 2003 - She Popped out....",$img,"Only because I went up her box....");
        		break;

        default:
                echo_thumbnail();
                break;
}

?>
Now, you can check it out here:
My Image Loader

What should happen, is when the thumbnail is clicked, a new window pops-up and the title is defined in the echo_image() tag. Also the comment is defined there too. Problem is, is that neither show up. If you view the source code, the variables aren't passed so the HTML looks like this:

Code: Select all

&lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;&lt;/TITLE&gt;&lt;META http-equiv=Content-Type content="text/html; charset=windows-1252"&gt;&lt;/HEAD&gt;&lt;BODY vLink=#009999 aLink=#0066CC link=#006666 bgColor=#006699&gt;&lt;P align=center&gt;&lt;IMG src="./images/2003halloweenFest01.jpg" border=0&gt;&lt;/P&gt;&lt;P align=center&gt;&lt;br&gt;&lt;FONT color=#FFFFFF&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P align=center&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;A href="./imageLoader.php"&gt;&lt;FONT face=Webdings color=#FFFFFF&gt;l&lt;/FONT&gt;&lt;/FONT&gt;&lt;/A&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;&lt;br /&gt;
&lt;b&gt;Fatal error&lt;/b&gt;:  Call to undefined function:  stop() in &lt;b&gt;/afs/umbc.edu/users/b/r/brett2/pub/www/phpimageLoader/imageLoader.php&lt;/b&gt; on line &lt;b&gt;8&lt;/b&gt;&lt;br /&gt;
How can I fix it?

Another problem (smaller yet easier) is the stop() function that I define. I call it so that the script stops there. Otherwise it creates two thumbnail pages, and a thumbnail page after the large image. So my question is:
What function can I call that will stop the script where I want it that won't cause it to error like it is now?

Thanks for the help you guys can offer.

~Brett Patterson

Posted: Thu May 13, 2004 3:49 am
by malcolmboston
exit; stops the script

or sleep(1) delays the script for 1 second

Posted: Thu May 13, 2004 4:04 am
by brett2
Thanks for that tip. Anyone have any ideas about the title and caption problem?

Posted: Thu May 13, 2004 4:32 am
by feyd
try changing:

Code: Select all

<?php 
$image_num = $_GET['img']; 
if($image_num != ""){ 
        echo_image($title,$image_num,$caption); 
}else{ 
        echo_thumbnail(); 
} 
stop();
to

Code: Select all

<?php
if(!empty($_GET['img']))
  $img = (int)$_GET['img'];
else
  {
    echo_thumbnail(); 
    exit;
  }
}
it appears you have register_globals on.. so you could change it to:

Code: Select all

<?php
if(empty($_GET['img']))
  {
    echo_thumbnail();
    exit;
  }
}

Posted: Thu May 13, 2004 5:19 am
by brett2
Ok, so I've adopted your code, and it now gives me warnings saying it's missing variables. Here's the code I'm using:

Code: Select all

if(empty($_GET['img'])){
		echo_thumbnail();
		exit;
}else{
		echo_image();
		exit;
}
And the error Message:

Code: Select all

Warning: Missing argument 1 for echo_image() in /afs/umbc.edu/users/b/r/brett2/pub/www/phpimageLoader/imageLoader.php on line 61

Warning: Missing argument 2 for echo_image() in /afs/umbc.edu/users/b/r/brett2/pub/www/phpimageLoader/imageLoader.php on line 61

Warning: Missing argument 3 for echo_image() in /afs/umbc.edu/users/b/r/brett2/pub/www/phpimageLoader/imageLoader.php on line 61
Thanks for the help.

~Brett

Posted: Thu May 13, 2004 5:23 am
by feyd
lose:

Code: Select all

else{
echo_image();
exit;
}
your switch statement will catch the $img global variable.

Posted: Thu May 13, 2004 5:27 am
by brett2
Ok, so I edited as you said, and now it just runs the Thumbnail script. Even when I click on a thumbnail it just brings up the thumbnail function.

~Brett

Check It Out Here

Code: Select all

if(empty($_GET['img']))
{
		echo_thumbnail();
		exit;
}

Posted: Thu May 13, 2004 6:58 am
by magicrobotmonkey
The reason it is only display the thumbnail agian is that either $GET['img'] is empty or it isnt set to 1-52, note your default switch case is the thumbnail. Now, what I would do is put that huge switch statement at the beginning like so:

Code: Select all

<?php
if(empty($_GET['img'])){ 
      echo_thumbnail(); 

}else{ 
   ####################################################################### 
#                                                                     # 
#    FUNCTION TO DEFINE THE TITLE, AND COMMENT OF THE LARGE IMAGES    # 
#                                                                     # 
####################################################################### 
  $img = $_GET['img']; 
  echo "Looks like its working! Searching for image number ".$img";
  switch($img){ 
        case 1: 
                echo_image("HalloweenFest 2003 - Stage",$img,"I was here"); 
                break; 

        case 2: 
                echo_image("HalloweenFest 2003 - The Grounds",$img,"The Grounds as viewed from the stage area"); 
                break; 

        case 3: 
                echo_image("HalloweenFest 2003 - Activities",$img,"Blow-Up Activities for the kids"); 
                break; 

        case 4: 
                echo_image("HalloweenFest 2003 - Group Shot 1",$img,"The Group... Need I say More?"); 
//etc
  }//end switch

}//end else

?>
Now, you can lose the exits to because there is nothing else to run because its all in functions. Better form, IMHO

Posted: Thu May 13, 2004 7:24 am
by brett2
AH HAH!!! That worked. Thank you so much.

~Brett

Posted: Thu May 13, 2004 7:35 am
by magicrobotmonkey
Nice!
Now you can lose this line, it was just for debugging:

Code: Select all

<?php
 echo "Looks like its working! Searching for image number ".$img;
?>

Posted: Thu May 13, 2004 7:43 am
by brett2
yes. Thank you very much.