1
Follow my complete code:
<?
include("conectar.php");
$query = "select * from pagseguro ORDER BY Referencia DESC";
$result = mysqli_query($db, $query) or die();
if($_REQUEST['alterarStatus']){
$status = trataaspas($_REQUEST['alterarStatus']);
$status_explode = explode("|", $status);
}
if($status_explode[0]=="aprovado"){
$SQL = "update pagseguro set StatusTransacao='Aprovado' where Referencia = '".$status_explode[1]."'";
}elseif($status_explode[0]=="completo"){
$SQL = "update pagseguro set StatusTransacao='Completo' where Referencia = '".$status_explode[1]."'";
}elseif($status_explode[0]=="cancelado"){
$SQL = "update pagseguro set StatusTransacao='Cancelado' where Referencia = '".$status_explode[1]."'";
}elseif($status_explode[0]=="devolvido"){
$SQL = "update pagseguro set StatusTransacao='Devolvido' where Referencia = '".$status_explode[1]."'";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" language="javascript">
function alterarStatusFunction(val){
if(val =="aprovado"){
if (confirm('Tem certeza que deseja alterar o status dessa transação para APROVADO?')) {
document.formtransacoes.submit();
} else {
return false;
}
}
else if(val =="completo"){
if (confirm('Tem certeza que deseja alterar o status dessa transação para COMPLETO?')) {
document.formtransacoes.submit();
} else {
return false;
}
}
else if(val =="cancelado"){
if (confirm('Tem certeza que deseja alterar o status dessa transação para CANCELADO?')) {
document.formtransacoes.submit();
} else {
return false;
}
}
else if(val =="devolvido"){
if (confirm('Tem certeza que deseja alterar o status dessa transação para DEVOLVIDO?')) {
document.formtransacoes.submit();
} else {
return false;
}
}
}
</script>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="10">
<? if(isset($total)){ if($total==0){?>
N/D
<? }else{ ?>
<tr><td>
<table width="100%" border="1" cellspacing="0" cellpadding="10" class="t-a">
<thead>
<tr class="th-a">
<th nowrap="nowrap" align="center" width="7%">Referência</th>
<th nowrap="nowrap" align="center">Opções</th>
</tr>
</thead>
<tbody>
<form name="formtransacoes" id="formtransacoes" action="" method="post">
<?
while($obj = mysqli_fetch_object($result)){
$statustranssacao = $obj->StatusTransacao;
?>
<tr>
<td nowrap="nowrap" align="center"><?=$obj->Referencia;?></td>
<td nowrap="nowrap" align="center">
<? if($obj->TransacaoID!=''){?>
<select style="width:200px" onchange="alterarStatusFunction(this.options[this.selectedIndex].title);" name="alterarStatus">
<option selected title="0">- Opções -</option>
<option disabled="disabled">------------------------------------------</option>
<? if($statustranssacao!='Aprovado' && $statustranssacao!='Completo'){?><option title="aprovado" value="aprovado|<?=$obj->Referencia;?>">Marcar como APROVADO</option><? } ?>
<? if($statustranssacao!='Completo' && $statustranssacao=='Aprovado'){?><option title="completo" value="completo|<?=$obj->Referencia;?>">Marcar como COMPLETO</option><? } ?>
<? if($statustranssacao!='Cancelado'){?><option title="cancelado" value="cancelado|<?=$obj->Referencia;?>">Marcar como CANCELADO</option><? } ?>
<? if($statustranssacao!='Devolvido'){?><option title="devolvido" value="devolvido|<?=$obj->Referencia;?>">Marcar como DEVOLVIDO</option><? } ?>
</select>
<? }else{ ?>
<span>Transação não iniciada!</span>
<? } ?>
</td>
</tr>
<? } } ?>
</form>
</tbody>
<? } ?>
</table>
</td></tr>
</table>
</body>
</html>
Can anyone tell me why it doesn’t work? It seems that it is not running the query to update the record of the selected item.
It has no connection to the database in its code or execution, it only has a string with the update
– rray
He’s in the connection file, I didn’t put him there.
– Wendler
But there’s one
mysqli_query()
or$pdo->query()
without that no sql statement is processed.– rray
I updated the code, take a look..
– Wendler
hehehe is the case that they think that we are Stackoverflownian beings endowed with superpowers that can guess what the code is
– user60252
I removed my response that was just to show that there is nothing wrong with SQL and that would be missing only the part to run the UPDATE, ie $data = mysqli_query($link, $SQL);
– user60252
@Leocaracciolo managed to make it work, knows some way to create a validation to show a message whether the query was executed or not?
– Wendler
boy, I was suspicious of that part, in the response I removed I had commented
Talvez na segunda parte, como estão sendo carregados os values
. Beauty that you achieved. Validation can be very simpleif($SQL){mensagem sucesso}else{erro}
You have more here https://stackoverflow.com/questions/2060325/need-to-test-if-sql-query-was-successful– user60252