heres the code for you to look at. I know about the php tags on this forum since I've been posting for a while.
// Prepare the query for execution
$sql = "INSERT INTO gallery_photos(photo_filename, photo_caption, photo_category) VALUES( ?, ?, ?)";
$results = $db->prepare($sql);
// Set the parameters
$results->bindParam(1, $photo_filename);
$results->bindParam(2, $photo_caption[$counter]);
$results->bindParam(3, $photo_category_id);
$photo_filename = '0';
// Execute the insert
$results->execute();
$results = null;
$sql = "SELECT category_name FROM gallery_category WHERE category_id='".$photo_category_id."'";
$results = $db->query($sql);
$photo_category = $results->fetch();
//echo $results;
// Retrieve the ID from the last insert
$new_id = $db->lastInsertId();
echo $new_id.'<br/>';
$filetype = $photos_uploaded['type'][$counter];
$extention = $photo_types[$filetype];
$filename = $new_id.".".$extention;
// Update the file name
try {
$select = $db->prepare("UPDATE gallery_photos SET photo_filename=? WHERE photo_id=?");
$select->bindParam(1,$filename);
$select->bindParam(2,$new_id);
$select->execute();
}
catch (PDOException $e) {
$db->rollback();
die(print "Error!: " . $e->getMessage() . "<br/>");
}
// Store the orignal file
copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$photo_category['category_name']."/".$filename);