Php error hard to find!

-7

Good morning.

I have the following snippet:

if (isset($_POST["acao"]) && $_POST["acao"]=="pgto")  {     

 if(empty($_SESSION["carrinho"])) {print 20;}
 if(!isset($_SESSION["carrinho"])) {print 40;}
      print "<pre>";
      print_r($_SESSION["carrinho"]);
      print "</pre>";
  if(empty($_SESSION["carrinho"]) || (!isset($_SESSION["carrinho"]))) {

      echo "<h1 class='erro'>Carrinho Vazio!</h1>";                 
      print "<pre>";
      print_r($_SESSION["carrinho"]);
      print "</pre>";

  } else {
      print "<pre>";
      print_r($_SESSION["carrinho"]);
      print "</pre>";       
     require_once "pedidoGravar.php";

     require_once "pedidoGravado.php";

     if (isset($_POST["pagamento"]) && $_POST["pagamento"]=="boleto")  {

         require_once "boleto.php";

     }

     if (isset($_POST["pagamento"]) && $_POST["pagamento"]=="pagseguro")  {

         require_once "pagSeguro.php";

     }

     if (isset($_POST["pagamento"]) && ($_POST["pagamento"]=="mastercard" || $_POST["pagamento"]=="visa"))  {

         require_once "cartao.php";

     }
  }
}

What happens is the following >

The session is usually printed on all

print_r($_SESSION["carrinho"]);

The code is normally entering both

if(empty($_SESSION["carrinho"]) || (!isset($_SESSION["carrinho"]))) { ...

How much in your else

} else {

          print "<pre>";
          print_r($_SESSION["carrinho"]);
          print "</pre>";

          require_once "pedidoGravar.php";
          require_once "pedidoGravado.php";
      }

What could be happening?

On page pedidoGravar.php I use the session to write to the bank and I unset the session of the cart.

In pedidoGravado.php , I display what was written to the bank normally.

But, it is normally passing both% w / o% and% w /%.

    
asked by anonymous 09.06.2016 / 14:27

2 answers

0

I was able to:

Actually there was no error occurring. It was that when I gave Ctrl + U to see the source code, Chrome updated the page (of the source code) and made a refresh . As of this page, it was also coming with data coming from a form post, in refresh , the page was reloaded (only in the source code) and then it entered the if that tests the cart.

I want to dedicate to the people who voted to close the doubt and my thanks to all who tried to help in some way: I know that without the project in hand it is difficult to find certain mistakes (that sometimes are not mistakes, lol) .

    
09.06.2016 / 20:22
-2

As I understand it, it is only passing through the if, so put:

 if(empty($_SESSION["carrinho"]) || (isset($_SESSION["carrinho"]))) {
    
09.06.2016 / 14:35