2
My situation,
A post form with a text input and two radios inputs.
Inputs are named respectively, nome[0]
and tipo[0]
.
When one adds more form fields I put one .attr to stay nome[1]
and tipo[1]
" and successively as it adds more inputs.
I did this to have how to transfer and prepare their information via POST in my php 'upload' file.
It also helped me keep the radio buttons in the same group on different lines.
At the end, I would like to put these records in the Mysql table in a table, in the spaces name and guy.
So was the PHP
<?php
include 'conexao.php';
$nome = $_POST['nome']; // Aqui pega input text, o valor do name="nome[0]".
$tipo = $_POST['tipo']; // Aqui pega do input radio, o valor do name="tipo[0]".
if (is_array($nome)){
if (is_array($tipo)){
foreach($nome as $valornome) {
foreach($tipo as $valortipo) {
$carimbo = $con->prepare("INSERT INTO ingressos (nome,tipo) VALUES (?,?)");
$carimbo->bindValue(1,$valornome,PDO::PARAM_STR);
$carimbo->bindValue(2,$valortipo,PDO::PARAM_STR);
$carimbo->execute();
}}}}
It went wrong, but...!
I am managing to store only the correct radios, the name is cloned by the number of inputs generated :(
Form
Here the Mysql
I’ve been seeing some in materials about before sending the data I have to organize the information I took from the vectors and then send, but I didn’t understand very well the texts I had access to...
In short, what is the path to situations like this? Imagining for example up to a third input option... I would love directions of themes and readings.
My knowledge is very artificial, I understand a little of what is happening but not the depth of the logic of the codes.
Thanks in advance!
The Insert went wrong this is the problem? the most practical is to leave the name of the fields like this
name="nome[]"
at the time of recovery are converted to an array.– rray