I'm building a table who have a button. When the user click this button the stat of row changes, in the table this represents a field with 0 or 1. Fine i'd made the button but i get an error in some rows, the error is Uncaught SyntaxError: missing ) after argument list, and i get very confused because the code works on like 80% of the time.
The problem wasn't with the database because i'd already searched for some field with problems.
function enviaAssociado(CTITULAR) {
if (CTITULAR) {
$("#CTITULAR").remove();
$.ajax({
url: 'php_action/enviaAssociado.php',
type: 'post',
data: {
CTITULAR: CTITULAR
},
success: function() {
manageTable.ajax.reload();
//$("#CTITULAR").val(response.CTITULAR);
}
});
}
manageTable.ajax.reload();
}
PHP
`
$CTITULAR = $_POST['CTITULAR'];
$sql = "UPDATE importsmiles4e.tb_conv
SET STAT = CASE
WHEN STAT = 1 THEN 0
WHEN STAT = 0 THEN 1
ELSE STAT
END
WHERE substring(CTITULAR,2,6) = '$CTITULAR'
";
$query = $connect->query($sql);
$CTITULAR = $_POST['CTITULAR'];
$sql = "UPDATE importsmiles4e.tb_conv3
SET STAT = CASE
WHEN STAT = 1 THEN 0
WHEN STAT = 0 THEN 1
ELSE STAT
END
WHERE substring(CTITULAR,2,6) = '$CTITULAR'";
$query = $connect->query($sql);
// close the database connection
$connect->close();
echo json_encode($sql);
`
The Table
while ($row = $query->fetch_assoc()) {
$active = '';
if($row['EMAIL'] != '') {
$active = '<label class="label label-success">Cadastrado</label>';
} else {
$active = '<label class="label label-danger">Cadastrar</label>';
}
$botao = '<a type="button" class="btn btn-default" onclick="enviaAssociado('.$row['CTITULAR'].') ">Alterar</a>';
$status = '';
if($row['STAT'] == '0'){
$status ='<label class="label label-warning">Não</label>';
}else{
$status ='<label class="label label-success">Sim</label>';
}
$output['data'][] = array(
$row['NOME'],
$row['CPF'],
$row['CEPRES'],
$row['NROPROPOSTA'],
$row['DTADMISSAO'],
$row['DEPENDENTES'],
$row['VLSMENS'],
$status,
$botao,
);
https://i.stack.imgur.com/KnD7w.png => error Log
https://i.stack.imgur.com/MhsDh.png => Return when error
The return when success is the same the only change is the value key and i've already check if the values are broken.