I'm using a "simple" script that I downloaded for an image galery, since it was a free script there is no support and although the script works great I need a simple modification so people can edit the information they provided with the picture they uploaded.

I manage to add to the script and the database a field to identify which user uploaded what, very basic user id.

Now I want to make the title of the picture a link to an another page where I would pull the information from the database and populate a form to be edited, this should not be a problem.

I already made the changes in the script for that although at this point the form hasen't been created yet, everything works fine if I use a hard value in the script but obviously I need this to be a variable which would be the value of the session $_SESSION['USERID'].

I thought this would be a very simple thing to do but my lack of knowledge of function class and OOP in general made it quite a bit harder than expected, some help would be greatly appreciated, attached is the relevant portion of the code.

// returns HTML code with the image /audio gallery in the specified category  
public function getGallery($gal='', $category='') {    
    $galery = '';           // to store the galery to be returned  

 // if parameters $gal, and $category not specified, gets their data from properties    
 if($gal == '') $gal = $this->gal;    
 if($category == '') $category = $this->category;    

 $rows = $this->selCategory($gal, $category);     // get the rows with files in specified $category    
 $nrows = count($rows);    

 // if not error, and at least one row, traverse the $rows, and create the HTML code for Galery, else, return error    
 if($this->eror === false && $nrows > 0) {      
    for($i=0; $i<$nrows; $i++) {        
        $url = $gal.'/'.$rows[$i]['category'].'/'.$rows[$i]['file'];       // the path to the file   

    // Sets in $galery the HTML code with data to be returned        
    // if image gallery, set link to image with thumbail, else, link to audio file        
    if($gal == $this->gimgs) {          
        $thumb = preg_replace('/(.*?)\.(gif|jpg|jpe|png)$/i', '${1}_thmb.${2}', $url);   
        //MY CODE
        $userid = "".$_SESSION['USERID']."";  // ASSIGN VALUE TO $userid
        if($rows[$i]['userid'] == '$userid'){ // IF I TRY SESSION HERE THE PAGE WON"T EVEN SHOW UP
        $galery .= '<div class="gimgs"><a href="http://www.genaide.ca/edit_image_gallery.php?id='.$rows[$i]['id'].'"><b>'.$rows[$i]['title'].'</b></a><br/><a href="'.$url.'" title="'.$rows[$i]['title'].'" target="_blank"><img src="'.$thumb.'" alt="'.$rows[$i]['title'].'" /></a><br/>'.$rows[$i]['descript'].'</div>';
            }else{       
        $galery .= '<div class="gimgs"><b>'.$rows[$i]['title'].'</b><br/><a href="'.$url.'" title="'.$rows[$i]['title'].'" target="_blank"><img src="'.$thumb.'" alt="'.$rows[$i]['title'].'" /></a><br/>'.$rows[$i]['descript'].'</div>'; 
        }

        }        
        else if($gal == $this->gaudio) {          
            $galery .= '<a href="'.$url.'" title="'.$rows[$i]['title'].'" target="_blank">'.$rows[$i]['title'].'</a> (<i>'.date('j-M-Y, H:i', $rows[$i]['dtreg']).'</i>)<blockquote>'.$rows[$i]['descript'].'</blockquote>';        
            }      
        }    
    }    
    else $galery = implode('<br/>', $this->eror);    

    return $galery;  
  }  
Member Avatar for LastMitch

@gamebits

I'm using a "simple" script that I downloaded for an image galery, since it was a free script there is no support and although the script works great I need a simple modification so people can edit the information they provided with the picture they uploaded.

I manage to add to the script and the database a field to identify which user uploaded what, very basic user id.

Now I want to make the title of the picture a link to an another page where I would pull the information from the database and populate a form to be edited, this should not be a problem.

I already made the changes in the script for that although at this point the form hasen't been created yet, everything works fine if I use a hard value in the script but obviously I need this to be a variable which would be the value of the session $_SESSION['USERID'].

I thought this would be a very simple thing to do but my lack of knowledge of function class and OOP in general made it quite a bit harder than expected, some help would be greatly appreciated, attached is the relevant portion of the code.

I'm bit confused what you said. Can you provide the link that where you got this code? You download this simple script and you try to modify it and mention that you are not familiar with function class and OOP? Why would you download a script that you don't understand how it works and expect someone to do the work? I'm learning OOP on my own so I know it's pretty difficult to understand. I'm surprise you would said you don't understand OOP and expect someone to do the work for you.

I'm a little confused by what you said too, you are saying that it's pretty difficult to understand and on the same breath you're bashing me for asking a question.

Secondly, I don't think I asked for someone to do the job for me, I already did most of it I need help for the last little thing that would allow me to tie everything together.

The question is quite simple, how do you use a session variable on this context? If I use the $_SESSION['USERID'] I end up with a blank page, if I assign the value to a variable $userid the script doesn't see it.

Member Avatar for LastMitch

@gamebits

I'm a little confused by what you said too, you are saying that it's pretty difficult to understand and on the same breath you're bashing me for asking a question.

Secondly, I don't think I asked for someone to do the job for me, I already did most of it I need help for the last little thing that would allow me to tie everything together.

The question is quite simple, how do you use a session variable on this context? If I use the $_SESSION['USERID'] I end up with a blank page, if I assign the value to a variable $userid the script doesn't see it.

Well, at least I'm learning it correct way since you just download this code and modify it and expect someone to finish what you started regarding about $_SESSION['USERID'].

You said it's a simple question then you should already know the answer than?

1081 posts, was anyone of them kind of useful?

Member Avatar for LastMitch

@gamebits

1081 posts, was anyone of them kind of useful?

Yes, I help members right now you're not helping yourself by doing that.

May be not, but you're not helping either, just saying.

Where exactly do you have the session_start ? And where you give value to $_SESSION['USERID'] ? ….

$_SESSION['USERID'] is set upon login and does have a value as verified with other part of the website, including the upload script for the images.

In the flow of execution do you have anywhere a session_start ?

To be more precise if you put

var_dump($_SESSION);
exit; 

before

$userid = "".$_SESSION['USERID'].""; 

Do you see what you expect the session to have ?

Just did and yes I have what I expect to see.

Member Avatar for LastMitch

@gamebits

May be not, but you're not helping either, just saying.

I would have down voted you for being sarcasm.

Well since, jkon is assisting you. I don't have to waste my time helping you instead helping other members who really need help.

So you have SESSION['USERID'] correct there as you say …and of course $userid (no reason for ."" to it) . So this is a variable inside a method … it can be accessed from inside this method … if you want other methods to use it you should make it private (for example) and assign values to it with $this->userid …

Bingo!! Got it to work, thank you jkon.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.