I've personally used Micah Carrick's Paypal IPN class.
When the user submits the form and the ID is generated, you can instantiate the class and do something like this:
$paypal = new paypal_class;
$paypal->add_field('business', YOUR EMAIL);
$paypal->add_field('notify_url', URL OF PROCESSING SCRIPT);
$paypal->add_field('item_name', ITEM NAME);
$paypal->add_field('amount', PRICE);
$paypal->add_field('currency_code', USD or GBP etc);
$paypal->add_field('custom', ID FROM DB INSERT);
$paypal->submit_paypal_post();
The custom field is the most important one for your purpose, you can put whatever you want here and it'll be returned with the IPN call to the *notify_url* script you have set.
On this notification page, you can validate the IPN call and retrieve the custom variable to do what you want with it...
$paypal = new paypal_class;
if ($paypal->validate_ipn()) {
$id = $paypal->ipn_data['custom'];
}
Remember to enable IPN callbacks in your Paypal account.