Jump to content

Help Needed with Receiving Postback from CCBill


RyanMinor

Recommended Posts

I am trying to retrieve certain keys of a post array. I am sending a payment form with a dynamic number of product id's. I will never know how many product id's will be sent for each order. When the post array returns the values to my script it returns them as:

 

$_POST['product_id_1'], $_POST['product_id_2'], etc.

 

How would I be able to extract all post array keys that start with "product_id_? Here is what I was thinking earlier, but it doesn't work.

 

$i = 1;
foreach ($_POST['product_id_' . $i] as $product) {
    $productId = $product['product_id_' . $i];
    $queryInsert = mysql_query("INSERT INTO video_purchase (video_purchase_purchase_id, video_purchase_video_id) VALUES ($purchaseId, $productId)", $connect) or die(mysql_error());
    $i++;
}

Link to comment
Share on other sites

They will be sequential and starting at 1. Below is the part of the form that will be generating the values:

 

<?php $i = 1;
foreach($_SESSION['cart'] as $video_id => $x) { ?>
    <input type="hidden" name="product_id_<?php echo $i; ?>" value="<?php echo $video_id; ?>" />
    <?php $i++;
} ?>

Link to comment
Share on other sites

Either one of the following methods will access just the product_id_x values -

<?php
$i = 1;
while(isset($_POST['product_id_' . $i])){
echo $_POST['product_id_' . $i] . '<br />';
$i++;
}

 

<?php
$keys = array_keys($_POST);
foreach($keys as $key){
if(strpos($key,'product_id_')===0){
	echo "Key: $key, Value: {$_POST[$key]}<br />";
}
}

 

If this is just within your code and is not a format that the gateway requires, you should use array names for the form field - http://us3.php.net/manual/en/faq.html.php#faq.html.arrays You will then be able to use a very simple foreach(){} loop to iterate over the $_POST['product_id'] array.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.