Hi everyone,
I’m building a shopping cart and everything works except the option to edit the number of products. Here is some of the code:
<form action="carrinho.php?action=edit" method="POST">
.
.
.
switch($_GET['action']) {
if (isset($_GET['action']))
{
if (isset($_GET['id']))
{
$id = $_GET['id'];
case "edit":
if (isset($_POST['quantidade']))
{
if (is_array($_POST['quantidade']))
{
foreach($_POST['quantidade'] as $id_produto => $quantidade)
{
if (is_numeric($quantidade))
{
$alterar_quantidade = mysql_query("UPDATE carrinho SET quantidade='$quantidade' WHERE id_produto='$id_produto', sessao='".session_id()."'") or die('Erro: ' . mysql_erro());
}
}
}
}
break;
.
.
.
<?php
include ("conexao.php");
$listagem = mysql_query("SELECT * FROM carrinho WHERE sessao='".session_id()."' ORDER BY nome ASC") or die('Erro: ' . mysql_error());
$contador_listagem = mysql_num_rows($listagem);
if ($contador_listagem != "")
{
$preco_total = 0;
while($row_listagem = mysql_fetch_assoc($listagem))
{
$preco_total += ($row_listagem['preco']*$row_listagem['quantidade']);
?>
<tr>
<td><?php echo $row_listagem['nome']; ?></td>
<td><?php echo number_format($row_listagem['preco'],3,",","") . "€"; ?></td>
<td><input type="text" size="3" name="quantidade[<?php echo $row_listagem['id_produto']; ?>]" value="<?php echo $row_listagem['quantidade']; ?>" />
</td>
<td><?php echo number_format($row_listagem['preco']*$row_listagem['quantidade'],3,",","") . "€"; ?></td>
<td><a href="carrinho.php?action=del&id=<?php echo $row_listagem['id_produto']; ?>">Remover</a></td>
</tr>
<?php
}
}
?>
<tr>
<td colspan="4">Total</td>
<td><?php echo number_format($preco_total,3,",",""); ?></td>
</table>
<input type="submit" value="Alterar"/>
</form>
When I edit the value on the page, it does nothing. I think the problem is somewhere on sending the value to my CASE.
Thanks in advance.