Reading array with php

Asked

Viewed 80 times

1

good afternoon, I have this array coming from variables $form

Array
(
    [nome] => 765hygfy
    [data_nascimento] => ftyftyf
    [email] => [email protected]
    [sexo] => Feminino
    [rg] => ytfytfyt
    [cpf] => fytfty
    [telefone_residencial] => fty
    [telefone_celular] => fyt
    [telefone_recado] => 
    [cep] => fytf
    [estado] => MS
    [cidade] => fytfytf
    [bairro] => ytf
    [logradouro_rua] => ftyf
    [numero] => tyfyt
    [complemento] => fty
    [referencia] => fytf
    [onde_conheceu] => FaceBook
    [revendeu_outras_marcas] => Não
    [quais] => ytftyf
    [horario_de_contato] => Manhã
)

they are coming from a form like the Names in this pattern

form[nome]
form[email]

and so it goes

what I need to do is php read this array by printing the key after value I’ve done several foreach until a go and turn blank.

my foreach

foreach($_POST['form'] as $key => $value){ 
  $nome = arrumanome($key);
  $msg.= $nome.": ".$value."<br>";
}

he only back Aki

:
:
:
:
:
:
:
:
  • What do you mean come back blank? What about the foreach structure?

  • edited with my foreach and q back

  • That way, it would be better to do 2 foreach: one with $_POST and the internal with the $value

  • can put html code too?

  • Takes the ['form'] of $_POST of foreach and see what returns.

  • look I did a var_dump of $_POST and it returns all variables and var_dump of $_POST['form'] and back the array right as I put in msg up there but the foreach is not printing the key or value.

  • Check the browser console and see if your server is not re-loading the page.

  • How is the HTML part? Would it be Ajax or Normal Form? Or the call is being made via Webservice?

Show 3 more comments

1 answer

0

Boy, it looks like you sent the blank form or that your namesake function is modifying your data and leaving them blank.

See if it helps you with the code below, which works properly:

An html form with some of your data to test:

<form action="foreach.php" method="post">

    <input type="text" name="form[nome]" value="Nome Teste"><br>
    <input type="text" name="form[data_nascimento]" value="31/01/1980"><br>
    <input type="text" name="form[email]" value="[email protected]"><br>
    <input type="text" name="form[sexo]" value="Masculino"><br>
    <input type="text" name="form[rg]" value="123456789"><br>
    <input type="text" name="form[cpf]" value="1198765432"><br>

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

</form>

foreach.php

<?php

$dados_post = $_POST["form"];

$msg='';

foreach($dados_post as $key => $value)
{
    $msg.= $key . ": " . $value . "<br>";
}

echo $msg;

Screen result:

nome: Nome Teste
data_nascimento: 31/01/1980
email: [email protected]
sexo: Masculino
rg: 123456789
cpf: 1198765432
  • ctz q he algono my apache coiei e colei o Cod Aki e continua em branco

  • It can be in the browser tb. Look at the source code of the page to see if there is something strange.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.