Interação php e mysql
Boa noite, tô precisando de ajuda no meu carrinho php, eu gostaria de estabelecer um formulario para preencher o endereço, e esse endereço ir pro banco de dados junto com o pedido, abaixo aqui ta meu arquivo carrinho e meu arquivo finalizar:
<
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style>
button{
border: 50;
padding: 10px 8px;
font-weight: bold;
color: #000000;
border-color: #000000;
background-color: #696969;
}
table, th, td {
border: 1px solid black;
}
th, td {
padding: 7px;
}
</style>
<body bgcolor="#FFFFFF">
<div align="center">
<p><a href="Template.html"><button onclick="document.getElementById('devolta').style.display='block'" class="w3-button w3-black">Voltar a página principal</button><a/></p>
</body>
<body>
<?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:
$_SESSION['dados'] =array();
$conexao = new PDO ('mysql:host=localhost;dbname=meusprodutos',"root", "");
?>
<table >
<thead>
<th>Nome</th>
<th>Preço</th>
<th>Quantidade</th>
<th>Subtotal</th>
<th>Opções</th>
</thead>
<tbody>
<?php
$totalcarrinho = 0;
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"];
if(count( $_SESSION['itens'] ) == 0 ) :
$totalcarrinho = 0;
else:
$tempcarrinho = $totalcarrinho;
$totalcarrinho = $tempcarrinho + $total;
endif;
?>
<tr>
<td><div align="center" style="font-size:20px; font-family: verdana"> <font color="black"><?=$produtos[0]["nome"]?></font> </div></td>
<td><?=number_format( $produtos[0]["preco"], 2, ", ", "." )?></td>
<td><div align="center"> <?=$quantidade?> </div></td>
<td><?=number_format( $total, 2, ",", "." )?></td>
<td><a href="remover.php?remover=carrinho&id=<?=$idProduto?>">Remover</a></td>
</tr>
<?php
array_push($_SESSION['dados'],
array ('id_produto' => $idProduto,
'quantidade' => $quantidade,
'preco' => $produtos[0]["preco"],
'total' => $total
)
);
endforeach;
?>
</tbody>
</table>
<table>
<td><div align='center' style='font-size:25px;font-family:Verdana'>Total <?=number_format( $totalcarrinho, 2, ",", "." )?></div></td>
</table>
<?php
echo '<a href="finalizar.php">Finalizar pedido</a>';
endif;
?>
</body>
</html>
>
agora o arquivo finalizar <
<!DOCTYPE html>
<html>
<style>
.container {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center
}
body {
margin: 0px;
}
h1 {
font-style: oblique;
font-family: monospace;
color: white;
}
.button1 {
border-top: 1px solid #344652;
background: #02304f;
background: -webkit-gradient(linear, left top, left bottom, from(#d6e0e6), to(#02304f));
background: -webkit-linear-gradient(top, #d6e0e6, #02304f);
background: -moz-linear-gradient(top, #d6e0e6, #02304f);
background: -ms-linear-gradient(top, #d6e0e6, #02304f);
background: -o-linear-gradient(top, #d6e0e6, #02304f);
padding: 17.5px 35px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: rgba(0,0,0,1) 0 1px 0;
-moz-box-shadow: rgba(0,0,0,1) 0 1px 0;
box-shadow: rgba(0,0,0,1) 0 1px 0;
text-shadow: rgba(0,0,0,.4) 0 1px 0;
color: #ffffff;
font-size: 22px;
font-family: Helvetica, Arial, Sans-Serif;
text-decoration: none;
vertical-align: middle;
}
.button1:hover {
border-top-color: #ffffff;
background: #ffffff;
color: #080508;
}
.button1:active {
border-top-color: #ffffff;
background: #ffffff;
}
</style>
<head>
<title></title>
</head>
<body bgcolor="#000000">
<div class="container">
<div align="center">
<h1>Compra realizada com sucesso<img src="certo.png" width="100" height="80"></h1><br><a href="template.html"><button class="button1" type="onclick">Voltar a comprar</button></a></h1>
</div>
</div>
</body>
</html>
>

Discussão (0)
Carregando comentários...