1

I am working on a form and it looks like this

<form name="project" method="post" action="result.php">
   Address: <input name="address[line1]" type="text"/>
</form>

In the result.php, I use the following code to get the input

<?php echo (isset ($_POST['address[line1]') ?  $_POST ['address [line1]'] : 'fail') ?>

However, I keep getting 'fail' on my page instead of catching the input address[line1], and the strange thing is when I change the name to "addressLine1" it works perfectly, can anyone advise me on this?

I am new to web development and I am pretty confused now.

2
  • Brackets [] are used for arrays. Plus, you're missing an if for your isset. Commented May 15, 2013 at 3:02
  • Thanks! Also just realize this by googling around! BTW, my isset works and I work this out by referring to davidwalsh.name/php-ternary-examples, any issue with this? @Fred Commented May 15, 2013 at 3:19

1 Answer 1

4

what you are after is $_POST["address"]["line1"] the array notation in the field name results in an array being created on the PHP side. In the future you can always just var_dump or print_r the contents of $_POST to see what is happening.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much. var_dump is quite useful!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.