开发者

$_GET variable cannot identify the first array element

$_GET variable cannot identify the first array element.:

I have passed an array in url which looks like this

http://www.example.com/form.php?action=buy_now&ft=prf&Arrayproducts_id[]=431&products_id[]=432&Arraycart[]=1&cart[]=3&Arrayid[]=431&id[]=432

but when i print the array "products_id" and "cart" by using print_r($_GET), it just display me

Array
(
    [0] => 432
)
Array
(
    [0] => 3
)

now as u can see the url it also contains the value "431" for products_id and "3" for cart I can see that due to the string "Array" appended to these they are not being accessed, So could someone suggest me how to fix this issue

EDIT as per Felix review

for($t=0;$t<4;$t++){

    $proid_30 .= "products_id[".$t."]=".$products_id."&";
        $bucket_30 .= "cart[".$t."]=".$_SESSION['qty_flex'][$t]."&";
        $idproid_30 .= "id[".$t."]=".$products_id."&";

        }
        $idproid_30.=" ";
$idproid_30 = str_replace("& ","",$idproid_30);
        echo "<script>window.location= '/print_ready_form.php?action=buy_now&ft=prf&".$proid开发者_如何转开发_30.$bucket_30.$idproid_30."&osCsid=".$_GET['osCsid']."';</script>";


Looks like you echo an array to create your URL. This does not work:

$a = array(1,2);
echo $a;

prints

Array

Can you show the PHP code that generates the URL?

Update:

Without more code I can only assume, but I think that $proid_30, $bucket_30 and $idproid_30 are initialized as arrays. Now when you append a string, they are casted to strings:

$a = array(1,2);
$a .= 'test';
echo $a;

prints

Arraytest

Use new variables to build the URL or initialize them as strings:

E.g.:

$product = '';
$cart = '';
$id = '';
for($t=0;$t<4;$t++){
    $product .= "products_id[".$t."]=".$products_id."&";
    $cart .= "cart[".$t."]=".$_SESSION['qty_flex'][$t]."&";
    $id .= "id[".$t."]=".$products_id."&";
}


you can use variable names like "var[]" in a http form. do you need to use only get method? try post


Its only displaying the 432 for products_id because the only other products_id in the link is called Arrayproducts_id.

You will need to rename this back to products_id =)

Unless you want to call Arrayproducts_id ofcourse.


First product Id was named as "Arrayproducts_id". So you can get by printing "Arrayproducts_id"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜