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?