Another PHP Question - Global Variable?

I’m working on a website using HTML with embedded PHP. You guys were so helpful with my last question, I thought I’d ask you another. My website will be an online, searchable photo gallery. It allows the user to upload JPEG photos to a folder on the server and store information about that photo in an SQL database. I have one form to upload the JPEG photo an another form to upload the information on the photo. Problem is, if you don’t get the name of the photo exactly into the database as it appears in the folder, the link to the photo in the database will not find the photo in the folder. I would like to trap the name of the JPEG photo in the page that uploads the photo and copy it into the page that inserts the record into the database. I’m thinking a global variable is the best way to to this since both actions occur on different pages, and I might want to do other things with the image name on other pages as well.

My PHP code to upload the photo to the folder is as follows:
$upfile = “/export/home/woodchuc/www/images/”.$userfile_name;
if (!copy($userfile, $upfile))
{
echo “Photo photo did not successfully copy into the IMAGES directory”;
exit;
}

echo “<h3>Photo Successfully Uploaded!<br>Click UPLOAD PIC INFO below to upload the photo information.</h3>”;

And, my PHP code to insert the record containing photo information into the SQL database is as follows:
mysql_select_db(“bn65807”);
echo “<p>Database Has Been Accessed!</p>”;

$query = “insert into bnsfloco (photo_id, road_number, locomotive_type, paint_scheme,
photo_month, photo_day, photo_year, location)
values
(’”.$photo_id."’ , ‘".$road_number."’, ‘".$locomotive_type."’, ‘".$paint_scheme."’,
‘".$photo_month."’, ‘".$photo_day."’, ‘".$photo_year."’, ‘".$location."’)";
$result = mysql_query($query);
echo “<h3>”;
echo "The information for your image “;
echo $photo_id;
echo " has been successfully uploaded!”;

The variable $photo_id is the record key variable I want to set to $userfile_name. How would I do this using global variables, or is there a better way?

I believe you’re asking: “I have some text (an image name) in one form page, and I want to make use of it in one or more other pages that will immediately be accessed after this current one.” If that’s it, I recommend you just pass the image name to the next page as a hidden parameter, i.e. link to page2.php?image=xxx.jpg.

And, this will be the second time I shamelessly plug my art site within the hour, but it has many similar features to what you’ve got, and I’m happy to share my source with you if you’d like. Don’t have upload features though. That’s currently done manually.

My suggestion is to merge the two forms, so you upload an image and the accompanying infomation at the same time.