2

I'm figuring this problem:
I have the $_POST['user'] variable. If I print_r this variable I get:

Array ( ['name'] => Your name ['phone'] => Your phone number ['email'] => Your email ) 

But if I try to use $_POST['user']['name'], nothing happens, it's an empty value.

It also happens if I set $_POST['user'] to a variable, for example $user, when I print_r $user I get the same array result, but if I try to work with $user['name'] it's blank.

This is the input data that has been submited

<input type="text" name="user['name']" value="Your name" class="general-user user-name-style" /> <input type="text" name="user['phone']" value="Your phone number" class="general-user user-data" /> <input type="text" name="user['email']" value="Your email" class="general-user user-data right-user" /> 

Am I working around in a wrong way with arrays?

7
  • Your approach looks ok, please share some code. Commented Oct 4, 2012 at 23:37
  • 2
    If $_POST['user']['name'] didn't exist, a warning/error would have been displayed. Your value is empty. Commented Oct 4, 2012 at 23:37
  • But when I print_r $_POST['user'], it shows me the value I submited "Your name", when I echo/print_r it directly, it shows nothing Commented Oct 4, 2012 at 23:42
  • @i.am.michiel, the code is as simple as this print_r($_POST['user']); //Displays things correctly print_r($_POST['user']['name']); //Nothing is shown Commented Oct 4, 2012 at 23:45
  • @i.am.michiel depending on error_reporting and display_errors, and it's only a notice. The default PHP config is rather unfriendly in this regard AFAIR. Commented Oct 4, 2012 at 23:48

2 Answers 2

3

The apostrophes are included in the keys, i.e. you get "'name'" as opposed to "name".
Try $_POST['user']["'name'"]

To solve the problem, remove the apostrophes from your HTML code:

<input type="text" name="user[name]" value="Your name" class="general-user user-name-style" /> <input type="text" name="user[phone]" value="Your phone number" class="general-user user-data" /> <input type="text" name="user[email]" value="Your email" class="general-user user-data right-user" /> 
Sign up to request clarification or add additional context in comments.

Comments

0

Check, maybe "name" has Cyrillic or other than regular Latin "a" or "e".

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.