tags:

views:

37

answers:

4

$_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>";
+2  A: 

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."&";
}
Felix Kling
+1 pls see the updated question
OM The Eternity
@OMThe Eternity: Can show more code? This seems to be only a part of it and I cannot find a problem there.
Felix Kling
this is it where the problem is Felix, as u said echo of url is creating the problem.. u r right for that..this is the place we have to make the correction for which i am not aware of
OM The Eternity
Yes U r right I have initialized them with "array();"
OM The Eternity
+1 Been trying to figure this out. But thanks to you, I learnt something new =)
Russell Dias
@OMThe Eternity, the problem is that `$proid_30` has some bad value in it *before* the loop you posted runs. So this loop is fine, the problem lies before this.
JSBangs
@OMThe Eternity: I think you have a misunderstanding here. You don't create arrays, you create strings that have more a less a special structure.
Felix Kling
Yes U r Right Again :) I misunderstood it... Thank YOU FELIX CAT.. DONT MIND YOUR NAME REMIND ME OF a Video GAME i used to play in my childhood
OM The Eternity
A: 

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

kgb
A: 

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.

Russell Dias
thats what the proble is i am not passing any of this key called "Arrayproducts_id" I want to remove this "Array" string attached in url
OM The Eternity
Are you able to edit the link which set this URL in the first place?
Russell Dias
plss see the update
OM The Eternity
Felix seems to have beaten me to the problem =)
Russell Dias
yup Russel Peters =)
OM The Eternity
A: 

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

sjamesas