Chuck Le Butt
Chuck Le Butt

Reputation: 48798

POST a multidimensional array -- Unable to see contents

I am POSTing a multidimensional array with the following fields in a HTML form:

 Member Name:
 <input name="teamMembers[<?php echo $i; ?>][Name]" type="text"
    id="teamMemberName1" maxlength="30" />
 Email: 
 <input name="teamMembers[<?php echo $i; ?>][Email]" type="text"
    id="teamMemberEmail1" maxlength="100" size="40" />

I can print_r($_POST['teamMembers']); and see the contents of the array, but when I try echo $_POST['teamMembers[0][Name]']; I get an "undefined index" error.

What am I doing wrong? (I'm sure it's something silly.)

Upvotes: 1

Views: 1845

Answers (1)

Sarfraz
Sarfraz

Reputation: 382806

You have wrong syntax:

echo $_POST['teamMembers[0][Name]'];

Should be:

echo $_POST['teamMembers'][0]['Name'];

More Info about Arrays in PHP.

Upvotes: 11

Related Questions