echo "<script>" does not work

Asked

Viewed 137 times

2

Good evening, I am trying to do a check on my website. If the customer balance, that is set by a $_SESSION.

If it has a balance less 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 Alert is not shown on the page and it only appears in Sponse (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.

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>;"); 

}
  • this is not correct. you have some syntax errors. do not concatenate "<script> with shop.php

Browser other questions tagged

You are not signed in. Login or sign up in order to post.