3
Good afternoon friends, I’m having a problem, I’m not able to register all users in BD, only only register the last, how can I solve this problem?
Index
<form method="post" action="salvar.php">
Name CPF Position - Function E-mail Kinship Stocks
<select name="cargo">
<option value="gerente" name="gerente">Gerente</option>
<option value="Professor" name="Professor">Professor</option>
<option value="Programador" name="Programador">Programador</option>
</select>
</td>
<td><input type="text" name="email"></td>
Remove
Add Dependents
Register
save php.
$nome = $_POST['nome'];
$cpf = $_POST['cpf'];
$cargo = $_POST['cargo'];
$email = $_POST['email'];
$parentesco = $_POST['parentesco'];
// faz consulta no banco para inserir os dados do usuario
$sql = "insert into cad_dependentes (nome, cpf, cargo, email, parentesco) values ('$nome', '$cpf', '$cargo', '$email', '$parentesco')";
function.js
(function($) {
RemoveTableRow = function(handler) {
var tr = $(handler).closest('tr');
tr.fadeOut(400, function(){
tr.remove();
});
return false;
};
AddTableRow = function() {
var newRow = $("<tr>");
var cols = "";
cols += '<td><input type="text" name="nome"></td>';
cols += '<td><input type="text" name="cpf"></td>';
cols += '<td><select name="cargo">';
cols += '<option value="gerente" name="gerente">Gerente</option>';
cols += '<option value="Professor" name="Professor">Professor</option>';
cols += '<option value="Programador" name="Programador">Programador</option>';
cols += '</select></td>';
cols += '<td><input type="text" name="email"></td>';
cols += '<td><input type="text" name="parentesco"></td>';
cols += '<td class="actions">';
cols += '<button class="btn btn-large btn-danger" onclick="RemoveTableRow(this)" type="button">Remover</button>';
cols += '</td>';
newRow.append(cols);
$("#products-table").append(newRow);
return false;
};
})(jQuery);
My friend, actually what’s wrong is the way he’s creating the form fields. To send more than one data via form, it is necessary to put the correct format for this. He put for example the name
name="gerente"
for each field. To work the way you did, it would have to change all the"name"
dynamic inputs to "name=gerente[]
"– Wallace Maxters