Opa,
I have a form in which I send via post the data of the form and capture by a forech.
In the form I have a button in which I create new inputs by append jquery, inputs with same name.
The problem I have is that when registering only one item, the Insert is performed normally, but when informing more items, only the first set of data is inserted, the second one is returned with values of 0.
The code to retrieve the values are:
foreach( $_POST['numero'] as $key => $n ) {
$data_cadastro = explode('/', $_POST['dt_cadastro'][$key]);
$data_cadastro = $data_cadastro[2].'-'.$data_cadastro[1].'-'.$data_cadastro[0];
$telefone_numero = str_replace("(", "", $_POST['numero'][$key]);
$telefone_numero = str_replace(")", "", $telefone_numero);
$telefone_numero = str_replace("-", "", $telefone_numero);
$telefone_numero = str_replace(" ", "", $telefone_numero);
$_POST['id_usuario'] = $_POST['id_usuario'][$key];
$_POST['numero'] = $telefone_numero;
$_POST['id_operadora'] = $_POST['id_operadora'][$key];
$_POST['dt_cadastro'] = $data_cadastro;
$_POST['status'] = $_POST['status'][$key];
$_POST['id_numero'] = $_POST['id_numero'][$key];
$result = DBCreate($tbl, $_POST, TRUE, TRUE);
}
When giving a print in the post, I get this:
Array
(
[id_usuario] => 3
[numero] => 82999999999
[id_operadora] => 1
[dt_cadastro] => 2016-04-14
[status] => 1
[id_numero] => 23232323
)
Array
(
[id_usuario] =>
[numero] => 2
[id_operadora] =>
[dt_cadastro] => --0
[status] =>
[id_numero] => 3
)
Is there something wrong with my foreach?
Fields of the same name have the same name, following a pattern: name="id_number []"
Check that when giving a print in the post before foreach I get:
Array
(
[id_usuario] => 31
[numero] => Array
(
[0] => (82) 99999-9999
[1] => (82) 8888-8888
)
[id_operadora] => Array
(
[0] => 1
[1] => 5
)
[dt_cadastro] => Array
(
[0] => 14/04/2016
[1] => 14/04/2016
)
[status] => Array
(
[0] => 1
[1] => 1
)
[id_numero] => Array
(
[0] => 23232323
[1] => 9830048884
)
)
That is, the values are correct before the foreach