-2
I have a form that is loaded through a comic while. the structure is this:
<form id="formulario" name="formulario" action="javascript:Func()" method="post">
<div id="div_prod">
<?php $sql_prod = mysql_query("SELECT bla bla bla");
while($sql= mysql_fetch_object($sql_prod )) { ; ?>
<input name="a" id="a" type="hidden" value="<?php echo $sql->a; ?>">
<input name="b" id="b" type="hidden" value="<?php echo $sql->b; ?>">
<input name="c" id="c" type="hidden" value="<?php echo $sql->c; ?>">
<button type="submit"><?php echo $sql->a; ?></button> <?php }; ?>
</div>
</form>
That is, the inputs of name a, b and c are generated n times, according to the amount of records that returns from select.
Ai, I have a function that adds the results in mysql, as below.
$("#formulario").submit(function() {
var a = $("#a").val();
var b = $("#b").val();
var c = $("#c").val();
$.post('../scripts/arquivo.php', {a: a, b: b, c: c}, function(resposta){
if (resposta != false) {
$("#status").html(resposta);
} else {
$("#status").html("Inserção realizada com sucesso!");
}
});
The process is working ok, however, it always loads only the first while product.
I tried to put the variables with name and id [] (ex: but does not send anything and gives no error.
Leaving without the [] only sends the first item.
How do I fix it?
Post the query structure in PHP, probably the error is in it
– MarceloBoni
Hello Marcelo. Thanks for the return. I just edited the post to make it easier to understand.
– NovatodaWeb
First hint, change the extension (obsolete)
mysql
formysqli
orpdo
– MarceloBoni
Right. Changed. Thanks. This influence only in the case of different versions of PHP, correct?
– NovatodaWeb
Like this your code now?
– MarceloBoni
Same thing.. I only changed mysql by mysqli
– NovatodaWeb
a good practice would be to use, instead of setting each input in a variable, the function
serialize()
jQuery, it would look something like this:var dados = $(this).serialize();
and put the name of your inputs as array. After that, just do the correct treatment in the file ../scripts/file.php to insert into the seat.– Whatyson Neves
I have no idea how to do :/
– NovatodaWeb