Skip to content

Instantly share code, notes, and snippets.

/carrinho.php
Created May 24, 2016

Embed
What would you like to do?
<?php
session_start();
if(isset($_GET['acao']) $_GET['acao'] == 'up'){
if(is_array($_GET['prod'])){
foreach($_GET['prod'] as $id => $qtd){
$id = intval($id);
$qtd = intval($qtd);
if(!empty($qtd) || $qtd <> 0){
$_SESSION['carrinho'][$id] = $qtd;
}else{
unset($_SESSION['carrinho'][$id]);
}
}
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="" id="update-cart">
Produto 1 : <input type="text" name="prod[1]" value="1" /><br />
Produto 2 : <input type="text" name="prod[2]" value="1" /><br />
Produto 3 : <input type="text" name="prod[3]" value="1" /><br />
<button type="submit">Atualizar</button>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script type="text/script">
jQuery(function($){
$("#update-cart").submit(function(e){
e.preventDefault();
var form = $(this).serialize();
window.location = 'carrinho.php?action=up&'+form
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.