2
I have 4 fields and wish to save in a db, however when putting in foreach ($_post['name'] as $name)... I do not know how to add more..
**DB**
id | vt | nome | qtn | id_cat
1 | 23 | qua..| 58 | 4
2 | 36 | não..| 57 | 2
register
<form action="php/cad.php" method="post">
<label>
<input type="button" class="btn btn-default" name="add" value="Add" />
</label>
<label>vt:</label>
<fieldset id="inputs_adicionais"></fieldset>
<input type="submit" value="Cadastrar" class="btn btn-default">
</form>
<script type="text/javascript">
$(document).ready(function(){
var input = '<label>Nome: <input type="text" name="vt[]" /> <input type="text" name="nome[]" placeholder="Nome"> <input type="text" name="qtn[]" placeholder="Qtn"> <input type="text" name="id_cat[]" placeholder="id cat"> <a href="#" class="remove">X</a></label>';
$("input[name='add']").click(function( e ){
$('#inputs_adicionais').append( input );
});
$('#inputs_adicionais').delegate('a','click',function( e ){
e.preventDefault();
$( this ).parent('label').remove();
});
});
</script>
db
<?php
include "conexao.php";
$vt = $_POST['vt'];
$nome = $_POST['nome'];
$qtn = $_POST['qtn'];
$id_cat = $_POST['id_cat'];
$sql = "INSERT INTO produto(vt, nome, qtn, id_cat) VALUES ('$vt', '$nome', '$qtn', '$id_cat')";
$query = $con->query($sql);
if($query!=null){
print "<script>window.location='../inicio.php';</script>";
}
?>
I don’t understand, I could explain better?
– Rafael Augusto
I added the full code. I have several fields to add and I would like to do this without having to register 1 by 1, so I need to register several and just click 1 time in "Register".
– Rafael
Will record a name per record or will record them all in one column (not a good idea)
– rray
DB:id | vt | name | qtn | id_cat New column will be created with its respective vt, name, qtn, id_cat.. In a form I will insert -> vt, name,qtn,id_car, click to add more and add more -> vt,name.... Then I register them all at once, each in its respective column
– Rafael