1

Everybody, I'm have an $_POST['input'] request with this:

Array
(
    ['Имя'] => 
    ['Город'] => 
    ['Контактный телефон'] => sdfsdf
    ['email'] => sdfsdf
    ['Площадь(м2)'] => 
    ['Материал'] => 
    ['Толщина стен(мм)'] => 
    ['Высота потолков(мм)'] => 
    ['Кол-во окон'] => 
    ['Топливо'] => 
    ['Пожелания'] => asdasd
)

How to get value of the element of this array, something like $_POST['input']['email'] for example (this does not work)?

3
  • how does your form looks like ? Commented Jan 21, 2015 at 11:55
  • How do you access your post array is based on your form and input elements. Commented Jan 21, 2015 at 12:01
  • Elements in form looks like this: <input style="width: 300px;" name="input['email']" /> Commented Jan 21, 2015 at 12:06

4 Answers 4

2

The issue here is that you have single quotes around the word 'email' inside the array key:

Notice the difference:

<?php

 $_POST['input'] = array ('...' => '...',
                          'email' => 'xyzabc',
                          "'email'" => 'sdfsdf');

Array
(
    [input] => Array
        (
            [...] => ...
            [email] => xyzabc
            ['email'] => sdfsdf
        )

)

So in order to correctly get the key you need to check it as follows:

if (isset($_POST['input']["'email'"])) {
     echo $_POST['input']["'email'"];
}

Result:

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

Comments

0

Do not write

$_POST['input']['email']

Write

echo $_POST['email']

And it will output sdfsdf

Comments

0

if this has been submitted though post request just look for $_post['email'].

Comments

0

$_POST['input']['email'] is the correct place to look.

Check if your the names are exact "email" (may be cirilic E in one of the places ?)

Try some of the others:

echo $_POST['input']['Имя']

You may need to check if the request is empty:

$email = isset($_POST['input']['email'])? $_POST['input']['email'] : 'no email';

1 Comment

Request is ok, think, something wrong with syntax, and braces, with you code:Array ( ['Имя'] => ['Город'] => ['Контактный телефон'] => sdfsdf ['email'] => sdfsdf ['Площадь(м2)'] => ['Материал'] => ['Толщина стен(мм)'] => ['Высота потолков(мм)'] => ['Кол-во окон'] => ['Топливо'] => ['Пожелания'] => asdasd ) no email

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.