I can’t show html in the middle of php

Asked

Viewed 59 times

-2

I’m trying to insert a cart that’s in html on a page php, the code inserted outside the php shows the cart normally. The library with the css is correctly invoked because it mounts the cart when placed outside, I would like to understand what might be happening. I’ve tried to put the built-in code in the middle of the php escaping the aspas and it didn’t even work.

The code I’m trying to insert html is this:

//MOSTRAR CARRINHO DE COMPRA
function carrinho(){
    //VERIFICAR SE EXISTE UMA SESSION
    if ($_SESSION){
        //SEPARAR NOME DE QUANTIDADE OU VALORES
        foreach($_SESSION as $nome => $quantidade){
                // VERIFICAR SE A QUANTIDADE NÃO ESTÁ ZERADA
            if ($quantidade > 0){
                    if(substr($nome,0,9) == 'produtos_'){

                    // Pegar ID da Session
                    $id = substr($nome,9,(strlen($nome) -9));                           

                    // MONTAR O CARRINHO
                    $PD = mysql_query("SELECT 
                                            `produtos`.id_produto, 
                                            `produtos`.`status`,
                                            `produtos`.nome,
                                            `produtos`.codigo_empresa                                               
                                            FROM
                                            `produtos`
                                            WHERE
                                            `produtos`.id_produto = '".mysql_real_escape_string( (int) $id)."' ");

                    while($list = mysql_fetch_assoc($PD)) {
                            $QTD = $quantidade;

                    ?>  

                        <div class="container">
                          <form class="cartContent clearfix" method="post" action="#">
                            <div id="cartContent"> 
                              <div class="item head"> <span class="cart_img"></span> <span class="product_name fsize13 bold">PRODUTO</span> <span class="remove_item fsize13 bold"></span> <span class="total_price fsize13 bold">TOTAL</span> <span class="qty fsize13 bold">QUANTITY</span>
                                <div class="clearfix"></div>
                              </div>
                              <div class="item">
                                <div class="cart_img"><img src="../assets/images/demo/shop/1.jpg" alt="" width="60" /></div>
                                <a href="shop-page-full-product.html" class="product_name"><span>Man shirt XL</span> </a> 
                                <a href="#" class="remove_item"><i class="fa fa-times"></i></a>
                                <div class="qty">
                                  <input type="text" value="1" name="total" maxlength="3" id="total" />
                                  </span></div>
                                <div class="qty">
                                  <input type="text" value="1" name="valor_unitario" maxlength="3" id="valor_unitario" />
                                  &times;

                                  <input type="text" value="1" name="quantidade" maxlength="3" id="quantidade" />

                                </div>
                                <div class="clearfix"></div>
                              </div>
                              <div class="clearfix"></div>
                            </div>
                          </form>
                        </div>  
                      <?php         
                    }//while
                }//if prod
            }// if qtd
        }//foreach
    }// if session

Contents of the $list variable:

Array ( [id_produto] => 1417 [status] => 1 [nome] => MANCAL DO PI NO DA BALANÇA Ø 50MM SEM TRAVA [codigo_empresa] => RO 0245 )
  • 1

    first check to be done, is entering WHILE?

  • Hello @Thiagosantos, yes, is entering the while.

  • How is your variable $list as soon as it enters the while?

1 answer

0

I managed to resolve this situation, by carelessness I had not realized that there was another form on my page, thus causing conflict and not allowing the correct rendering of the page. Problem solved.

Browser other questions tagged

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