echo "script" does not work

2

Good evening, I'm trying to do a check on my site. If the client balance, which is set by a $ _SESSION.

If it has a balance lower than the price of the product, it would have to do this:

$saldo = $_SESSION['saldo'];

$procuraPreco = mysqli_query($connect, "SELECT preco FROM infs WHERE id='$id'"); 

$retornaPreco = mysqli_fetch_all($procuraPreco,MYSQLI_ASSOC);

$preco = $retornaPreco[0]['preco'];
if(isset($_POST['comprar'])) {
if($saldo < $preco) {
die('<script>alert("Pedido recusado. Razão: Saldo insuficiente"); window.location = "shop.php";</script>;'); 

}

Only the alert is not shown on the page and it only appears in the response (F12):

<script>alert("Pedido recusado. Razão: Saldo insuficiente"); window.location = "shop.php";</script>

Note: I do a POST on the same page that the customer clicks to buy.

    
asked by anonymous 28.08.2018 / 03:44

1 answer

-3

Try this

$procuraPreco = mysqli_query($connect, "SELECT preco FROM infs WHERE 
id='$id'"); 

$retornaPreco = mysqli_fetch_all($procuraPreco,MYSQLI_ASSOC);

$preco = $retornaPreco[0]['preco'];
if(isset($_POST['comprar'])) {
$saldo = $_SESSION['saldo'];

if($saldo < $preco) {
echo die("<script>alert("Pedido recusado. Razão: Saldo insuficiente"); 
window.location = "shop.php";</script>;"); 

}
    
28.08.2018 / 03:50