I have a page with a table and data coming from the bank, this page has automatic refresh, the data is coming from another page (getdados.php), this table has a column called status, which by default when inserted in BD it goes as available, in this same column I added a button to change the status to: pending and collapsed, but my javascript function is not working, what's wrong?
getdados.php file
<script>
$(document).ready(function(){
$('#sel1').on('change', function(){
var selecionado = $('#sel1').val();
$.ajax({
data: 'selecionado='+selecionado,
type: 'post',
url: 'status.php',
});
});
});
<?php
//Conectando ao banco de dados
$con = new mysqli("localhost", "root", "", "tcc");
if (mysqli_connect_errno()) trigger_error(mysqli_connect_error());
//Consultando banco de dados
$qryLista = mysqli_query($con, "SELECT * FROM postagens");
while($r = mysqli_fetch_assoc($qryLista)){
?>
<table id='tabela'>
<tr>
<td><?= $r['id'] ?></td>
<td><?= $r['nome'] ?></td>
<td><?= $r['rua'] ?></td>
<td><?= $r['bairro'] ?></td>
<td><?= $r['telefone'] ?></td>
<td><?= $r['descricao'] ?></td>
<td>
<select id='sel1'>
<option value='status'><?= $r['status'] ?></option>
<option value='pendente'>Pendente</option>
<option value='recolhido'>Recolhido</option>
</select></td>
</table>
<?php
}
?>
status.php file
<?php
include_once("setting.php");
$escolha = filter_input(INPUT_POST,'selecionado');
if($escolha === 'recolhido'){
$sql = "UPDATE postagens SET status = $escolha'";
$res = mysqli_query($conn, $sql);
$linhas = mysqli_affected_rows($conn);
echo $linhas;
if ($linhas ==1){
echo "sucesso";
}else{
echo "erro";
}
}else{
}
?>