I have setup a PayPal IPN file. When the user is at the site and press submit details about the transaction is uploaded to the db. The relevant id is sent via PayPal as the
I did just this recently,
Send your paypal custom field to data as your would, inside that custom field, use a separator to split your data.
In the below example, the values are split using a "|", you can use any character you want available in your charset.
$member_id = 1;
$some_other_id = 2;
<input type="hidden" name="custom" value="<?php echo $member_id.'|'.$some_other_id ?>"/>
This will output:
<input type="hidden" name="custom" value="1|2"/>
When you get the information from paypal (the IPN response) process it like so:
$ids = explode('|', $_POST['custom']); // Split up our string by '|'
// Now $ids is an array containing your 2 values in the order you put them.
$member_id = $ids[0]; // Our member id was the first value in the hidden custom field
$some_other_ud = $ids[1]; // some_other_id was the second value in our string.
So basically, we send a string with a custom delimiter that we choose to paypal, paypal will return it to us in the IPN response. We then need to split it up (using the explode() function) and then do what you would like with it.
When you get your value from the database your select it using normal methods, then just decrement it by 1 using:
$val_from_db--; // Thats it!, Takes the current number, and minus 1 from it.
Here is an example using JSON:
<?php
$arr = array($member_id, $coupon);
$data = json_encode($arr);
?>
<input type="hidden" name="custom" value="<?= $data ?>"/>
Then on the other side:
$custom = json_decode($_POST['custom'], true);
$member_id = $custom[0];
$coupon = $custom[1];
You can also parse associative arrays too:
<?php
$arr = array('id' => $member_id, 'coupon' => $coupon);
$data = json_encode($arr);
?>
<input type="hidden" name="custom" value="<?= $data ?>"/>
Then on the other side:
$custom = json_decode($_POST['custom'], true);
$member_id = $custom['id'];
$coupon = $custom['coupon'];
There's a nice symmetry when using JSON to parse the data.
This expands on JustAnil's solution.
HTML:
<input type="hidden" name="custom" value="some-id=1&some-type=2&some-thing=xyz"/>
and your IPN script would look something like this:
<?php
parse_str($_POST['custom'],$_CUSTOMPOST);
echo $_CUSTOMPOST['some-id'];
echo $_CUSTOMPOST['some-type'];
echo $_CUSTOMPOST['some-price'];
?>
You may want to double check that parse_str performs urldecode on resulting array elements.