0
I have a page with a table and data coming from the database, 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 it is inserted in the BD it goes as available, in this same column I added a button to change the status to: pending and collected, but my javascript function is not working, which is wrong?
getdados file.php
<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
}
?>
php status 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{
}
?>
Even call the url, status.php? Guy I think one is missing
WHERE
, in your SQL, this is not what is causing it to fail, but the way it is will update in your entire table.– Flávio Silva
yes I called him in getdados.php, where do I put the function? in the file that is the table? or in getdados msm?
– caio
Set "not working". What happens? Gives error ? Confirm on browser inspection. If yes what error appears ? Take advantage and also confirm in the network tab of the inspect if the orders are being made and what data has in them.
– Isac
not changing the status in the bank, my doubt and the following, I would just like to know if the function is right, if I am passing the value correctly to the function, if I have to pass the id of the record I will change, as I pass to the function.
– caio