0
I have a list of names that come from the database and I need to update these names when necessary. I bring everyone already inside the form and update with a Javascript.
With a record works perfectly. The problem is when I bring more than one name from the bank, hence it only works on the first form.
<?php
$consulta = mysql_query("
SELECT * FROM categoria limit 2");
while ($dados = mysql_fetch_array($consulta)) {
?>
<form method="POST" action="" id="ajax_form">
<div class="row">
<div class="col-md-6 form-group">
<input type="text" id="id_categoria" name="id" class="form-control" value="<?echo$dados['id_categoria']?>" readonly>
<input type="text" id="nome" name="nome" class="form-control" maxlength="100" placeholder="Seguimento" value="<?echo$dados['nome']?>" required autofocus>
<button class="btn btn-primary" type="submit">Atualiza</button>
</div>
</div>
</form>
<?}?>
JS
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#ajax_form').submit(function(){
var data = {
id_categoria: $('#id_categoria').val(),
nome: $('#nome').val()
};
$(this).text("Atualizando"); // Aqui voce muda o texto do botao caso queira
$.ajax({
type: "POST",
url: "seguimento_lista_sql_update.php",
data: data,
cache: true
})
});
});
</script>
Select the code that updates, that is, the following page_lista_sql_update.php ?
– denis