1
I am developing an ad system, where it is possible to send offers to the ad owner and then carry out the approval or rejection of the offer, if you approve and then negotiate with those who offered.
I came across a problem: When you only have one offer I can approve or reject, but if you have more than one offer when I click on an option it does this for all offers...
I did a search here for the forum, but I didn’t find anything like it.
Follow the code (Obs: when I played the code here it messed up the indentation):
<div class="container2">
<div class="col-sm-10">
<div class="row">
<div class="titulo_1">
<h1>Ofertas recebidas</h1>
</br>
</div>
<?php
$id_usuario = $_SESSION["id"];
$anuncio = $_GET["id"];
$sql = "SELECT * FROM ofertas = OF
INNER JOIN anuncios = AN
ON OF.id_anuncio = AN.ID
WHERE AN.id_usuario = '$id_usuario' AND OF.status = 'ANALISE'";
while($sql = mysql_fetch_array($query2))
{ ?>
<div class="col-sm-3">
</br>
<div class="text-center"><strong>ID do usuário que enviou a oferta: </strong><?php echo $sql['id_usuario_oferta']; ?></div>
<div class="text-center"><strong>ID da oferta: </strong><?php echo $sql['ID_OF']; ?></div>
<div class="text-center"><strong>ID do anúncio: </strong><?php echo $sql['ID']; ?></div>
<div class="text-center"><strong>Usuário que enviou a oferta: </strong><?php echo $sql['nomeusuario_oferta']; ?></div>
<div class="text-center"><strong>Produto: </strong><?php echo $sql['produto']; ?></div>
<div class="text-center"><strong>Valor oferta: </strong><?php echo $sql['valoroferta']; ?></div>
<div class="text-center"><strong>Valor de recompensa que você informou: </strong><?php echo $sql['valorrecompensa']; ?></div>
<div class="text-center"><strong>Viagem que ele irá fazer: </strong><?php echo $sql['viagemcompra']; ?></div>
<div class="text-center"><strong>Comentário: </strong><?php echo $sql['comentario']; ?></div>
<div class="text-center"><strong>Oferta enviada em: </strong><?php echo $sql['dataoferta']; ?></div>
</br>
<form method="post" action="">
<button type="submit" name="aceitar" id="aceitar" value="NEGOCIACAO"class="btn btn-success btn-flat">Aceitar</button>
<button type="submit" name="rejeitar" id="rejeitar" value="REJEITADO" class="btn btn-danger btn-flat">Rejeitar</button>
</form>
<?php
$IDoferta = $sql['ID_OF'];
if(isset($_POST['aceitar'])) {
$query = "UPDATE ofertas SET status = 'NEGOCIACAO' WHERE ID_OF = '$IDoferta'";
mysql_query($query);
echo "<meta http-equiv='refresh' content='0, url=index.php'";
} ?>
<?php
$IDoferta = $sql['ID_OF'];
if(isset($_POST['rejeitar'])) {
$query = "UPDATE ofertas SET status = 'REJEITADO' WHERE ID_OF = '$IDoferta' LIMIT 1";
mysql_query($query);
echo "<meta http-equiv='refresh' content='0, url=index.php'";
} ?>
</div>
<?php
} ?>
</div>
This error usually happens when there is an error in the clause
where
sql, which instead of making the change on a database line, by id for example, does it to all rows. I think the error is after Where. Exchange the'$IDoferta'
for" + $IDoferta + "
– Costamilam
Opa William, thank you very much friend! I managed to resolve with the answer below.
– Felipe Lemes