<?php
session_start();
if (!isset( $_SESSION['itens'] ) ):
$_SESSION['itens'] = array();
endif;
if ( isset( $_GET['add'] ) && $_GET['add'] == "carrinho" ):
$idProduto = $_GET['id'];
if (!isset ($_SESSION['itens'][$idProduto])):
$_SESSION['itens'][$idProduto] = 1;
else:
$_SESSION['itens'][$idProduto] +=1;
endif;
endif;
if ( count( $_SESSION['itens'] ) == 0 ):
echo 'Carrinho vazio<br><a href="template.html">Adicionar itens</a>';
else:
$conexao = new PDO ('mysql:host=localhost;dbname=meusprodutos',"root", "");
?>
<table>
<thead>
<th>Nome</th>
<th>Preço</th>
<th>Quantidade</th>
<th>Total</th>
<th>Opções</th>
</thead>
<tbody>
<?php
foreach ( $_SESSION['itens'] as $idProduto => $quantidade ):
$select = $conexao->prepare("SELECT * FROM produtos WHERE id=?");
$select ->bindParam(1, $idProduto);
$select ->execute();
$produtos = $select->fetchAll();
$total = $quantidade * $produtos[0]["preco"];
?>
<tr>
<td><?=$produtos[0]["nome"]?></td>
<td><?=number_format( $produtos[0]["preco"], 2, ", ", "." )?></td>
<td><?=$quantidade?></td>
<td><?=number_format( $total, 2, ",", "." )?></td>
<td><a href="remover.php?remover=carrinho&id=<?=$idProduto?>">Remover</a></td>
</tr>
<?php
endforeach;
?>
</tbody>
</table>
<?php
endif;
?>
Lembro que não é o ideal, mas é algo com base no seu código, lembre-se verificar se a conexão com o servidor sql está funcionando antes de realizar a query.