0
My application consists of an html page in which the user informs the code of a product, the quantity, and it is shown below. Behold, if I add a product, it is inserted but does not return. And when I continue to add items, only the following records are listed.
<?php
include_once("Classes\CONEXAO_BD.php");
session_start();
echo $ID_PEDIDO = $_SESSION['novo_id'];
//Início da listagem
$servidor = 'localhost';
$usuario = 'root';
$senha = '';
$banco = 'portfolio';
//Sql para listar os produtos adicionados
$comando_sql_listagem = "SELECT * FROM item_pedido INNER JOIN calcado ON item_pedido.ID_CALCADO = calcado.ID_CALCADO WHERE ID_PEDIDO = '".$ID_PEDIDO."' ";
//Sql para calcular o preço dos produtos
$comando_sql_soma = "SELECT SUM(PRECO) FROM calcado INNER JOIN item_pedido ON calcado.ID_CALCADO = item_pedido.ID_CALCADO WHERE ID_PEDIDO = '".$ID_PEDIDO."' ";
$link = mysqli_connect($servidor,$usuario,$senha,$banco);
$resultado_listagem = mysqli_query($link,$comando_sql_listagem) or die (mysqli_error($link));
$linha = mysqli_fetch_assoc($resultado_listagem);
$resultado_soma = mysqli_query($link,$comando_sql_soma) or die (mysqli_error($link));
$total = mysqli_fetch_assoc($resultado_soma);
?>
Listing:
<?php
if(!empty($linha))
{
while($linha = mysqli_fetch_assoc($resultado_listagem) )
{
?>
<tr>
<td data-title="ID"><?php echo $linha['ID_CALCADO']; ?></td>
<td data-title="NOME"><?php echo $linha['NOME']; ?></td>
<td data-title="NOME"><?php echo $linha['TAMANHO']; ?></td>
<td data-title="COR"><?php echo $linha['QUANTIDADE']; ?></td>
<td data-title="VALOR">R$ <?php echo $linha['PRECO']; ?></td>
<td data-title="">
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#excluir" data-cpf="">
Excluir
</td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td colspan="5">
<center>
<?php
echo "Nenhum produto adicionado";
?>
</center>
</td>
</tr>
<?php
}
?>
Entry code in the database:
<?php
include_once("Classes/CONEXAO_BD.php");
$ID_CALCADO = $_GET["ID_CALCADO"];
$QUANTIDADE = $_GET["QUANTIDADE"];
$ID_PEDIDO = $_GET["ID_PEDIDO"];
$TAMANHO = $_GET["TAMANHO"];
$comando_sql = "insert into item_pedido (ID_CALCADO,QUANTIDADE,ID_PEDIDO,TAMANHO) values ('".$ID_CALCADO."' , '".$QUANTIDADE."' , '".$ID_PEDIDO."' , '".$TAMANHO."') ";
$nova_conexao = new CONEXAO_BD();
$nova_conexao->Abrir_conexao($comando_sql);
?>
<script type="text/javascript">
window.location.href="cadastro_pedido.php";
</script>
Can Wellingthon give more details?! You can see that where you comment: //Sql to calculate the price of products I believe that if your intention is to add the total order, you also need to consider the quantities... Ex: SELECT SUM(calcado.PRECO * item_pedido.QUANTIDADE) FROM calcado INNER JOIN item_pedido ON...
– Bruno Lopes
Is the query not being made before the inclusion? What is the code that makes the product insertion?
– Filipe Ricardo
Yes, but if the query is empty, a message appears. Otherwise, the listing (incomplete appears on the screen)
– Igor
Sorry if the question is too stupid, but the item that does not appear is in the two tables,
item_pedido
andcalcado
? The query may not be returning the record because ofINNER JOIN
... On the same line, you can also show theINSERT
?– nunks
You need to put all the code, especially the INSERT part for us to analyze, I believe that the INSERT is being done after the query, so the product inserted is not in the query
– Filipe Ricardo
Yes, the item appears in both tables. In the 'trampled' table the items have already been entered previously, so I use the code above to insert the data in the other table (item_requested). I also suspect that it is INNER JOIN, but I do not know what other query would return me all records
– Igor
Your code should be in the first select: item_request.id_calcado = calcado.id and in the second select: calcado.id = item_request.id_calcado, I ask you to put create table as code to analyze
– Wilson Rosa Gomes