Page 1 of 1

<input name="array[]"> not working

Posted: Sat Jun 21, 2008 7:21 am
by smcalpine
Hello (first post)

On my live server a shopping cart script has stopped working and I have worked out the issue is that arrays are not being passed using POST and the square bracket array notation.

I created 2 short scripts to demonstrate:

basictest1.php

Code: Select all

 
<html>
<head>
    <title>Basic Test</title>
</head>
<body>
    <form name="form1" enctype="multipart/form-data" action="basictest2.php" method="POST">
 
        <label for="arraytest1">Array[0]</label>
        <input type="text" name="arraytest[]" id="arraytest1"><br />
 
        <label for="arraytest1">Array[1]</label>
        <input type="text" name="arraytest[]" id="arraytest2"><br />
 
        <label for="stringtest">String</label>
        <input type="text" name="stringtest" id="stringtest"><br />
 
        <input type="submit" value="Submit">
 
    </form>
</body>
</html>
 
basictest2.php

Code: Select all

<?php
 
die(print_r($_POST));
 
?>
The results are:
arraytest is not available using POST
stringtest is available using POST

If I change the form method to GET then it works as expected.

Can someone please help? I'm tearing my hair out as I have never experienced anything like this.

I am using PHP 5.2.6. I would post my full phpinfo() for reference but I can't .htm/.php/.txt files!

Thanks.

Stuart

Re: <input name="array[]"> not working

Posted: Mon Sep 08, 2008 9:05 am
by adroit
smcalpine wrote:Hello (first post)

On my live server a shopping cart script has stopped working and I have worked out the issue is that arrays are not being passed using POST and the square bracket array notation.

I created 2 short scripts to demonstrate:

basictest1.php

Code: Select all

 
<html>
<head>
    <title>Basic Test</title>
</head>
<body>
    <form name="form1" enctype="multipart/form-data" action="basictest2.php" method="POST">
 
        <label for="arraytest1">Array[0]</label>
        <input type="text" name="arraytest[]" id="arraytest1"><br />
 
        <label for="arraytest1">Array[1]</label>
        <input type="text" name="arraytest[]" id="arraytest2"><br />
 
        <label for="stringtest">String</label>
        <input type="text" name="stringtest" id="stringtest"><br />
 
        <input type="submit" value="Submit">
 
    </form>
</body>
</html>
 
basictest2.php

Code: Select all

<?php
 
die(print_r($_POST));
 
?>
The results are:
arraytest is not available using POST
stringtest is available using POST

If I change the form method to GET then it works as expected.

Can someone please help? I'm tearing my hair out as I have never experienced anything like this.

I am using PHP 5.2.6. I would post my full phpinfo() for reference but I can't .htm/.php/.txt files!

Thanks.

Stuart



Hi Stuart,

Try using below code. Create one single page and paste this code.

<?php
echo "<pre>";
print_r($_REQUEST);
echo "</pre>";
?>

<html>
<head>
<title>Basic Test</title>
</head>
<body>
<form name="form1" enctype="multipart/form-data" action="" method="POST">

<label for="arraytest1">Array[0]</label>
<input type="text" name="arraytest[]" id="arraytest1"><br />

<label for="arraytest1">Array[1]</label>
<input type="text" name="arraytest[]" id="arraytest2"><br />

<label for="stringtest">String</label>
<input type="text" name="stringtest" id="stringtest"><br />

<input type="submit" value="Submit">

</form>
</body>
</html>

Regards,
Adroit
http://www.adroitsoftware.org