Во-первых, здесь мы можем увидеть файлы index.php, cart.html.php и catalog.html.phpКорзина 'Удалить' кнопка ввода не работает
файл index.php
<?php
$items = array(
array("id" => '1', "name" => 'Meitantei Conan/Case Closed', "category" => "Comics & Manga", "desc" => "nodesc", "price" => '4'),
array("id" => '2', "name" => 'Harry Potter and the Philopher\'s stone', "category" => "Books", "desc" => "nodesc", "price" => '20'),
array("id" => '3', "name" => 'Harry Potter lol', "category" => "Lolling", "desc" => "nodesc", "price" => '20'),
array("id" => '4', "name" => 'My Harry Potter', "category" => "Junk", "desc" => "nodesc", "price" => '20'),);
session_start();
if(!isset($_SESSION['cart'])) {
$_SESSION['cart'] = array();
}
if(isset($_POST['action']) && ($_POST['action']) == "Buy") {
$_SESSION['cart'][] = $_POST['buyid'];
header('Location .');
}
if(isset($_POST['action']) && $_POST['action'] == 'Empty Cart') {
unset($_SESSION['cart']);
header('Location: ?cart');
exit();
}
if(isset($_GET['paypal'])) {
echo "I will add here paypal and other things..";
exit();
}
if(isset($_GET['cart'])) {
$cart = array();
$total = 0;
foreach($_SESSION['cart'] as $id) {
foreach($items as $product) {
if($product['id'] == $id) {
$cart[] = $product;
$total += $product['price'];
break;
}
}
}
include 'cart.html.php';
exit();
}
if(isset($_POST['del']) && ($_POST['del']) == 'Delete') {
if(isset($_GET['del'])) {
$cart = array();
$delid = $_POST['delid'];
foreach($_SESSION['cart'] as $id) {
foreach($items as $product) {
if($product['id'] == $delid) {
unset($_SESSION['cart'][$delid]);
}
}
}
}
}
include 'catalog.html.php';
catalog.html.php файл
<?php
if(!isset($_COOKIE['visits'])) {
$_COOKIE['visits'] = 0;
}
$visits = $_COOKIE['visits'] + 1;
setcookie('visits', $visits, time() + 3600 * 24 * 365);
?>
<!DOCTYPE html>
<html lang="it">
<head><title>Products Catalog</title>
<style>
table {
border-collapse: collapse;
}
td, th {
border: 1px solid black;
}
</style>
</head>
<body>
<?php global $visits;
if($visits > 1) {
echo "<h2>Welcome back!! Visit number: $visits</h2>";
}
else echo "<h2>Welcome! This is your first visit!</h2>";
?>
<p>Your cart contains <?php echo count($_SESSION['cart']); ?> items.</p>
<p><a href="?cart">View your cart</a></p>
<table border="1">
<thead>
<tr>
<th>Item Name</th>
<th>Item Desc</th>
<th>Item Category</th>
<th>Price</th>
<th>Options</th>
</tr>
</thead>
<tbody>
<?php foreach($items as $item): ?>
<tr>
<td><?php echo $item['name']; ?></td>
<td><?php echo $item['desc']; ?></td>
<td><?php echo $item['category']; ?></td>
<td>$<?php echo number_format($item['price'], 2); ?></td>
<td><form action="" method="post">
<div>
<input type="hidden" name="buyid" id="buyid" value="<?php echo $item['id']; ?>">
<input type="hidden" name="price" id="price" value="<?php echo number_format($item['price'], 2); ?>">
<input type="submit" name="action" id="action" value="Buy">
</div>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>
А потом, файл cart.html.php
<?php
if(!isset($_COOKIE['visits'])) {
$_COOKIE['visits'] = 0;
}
$visits = $_COOKIE['visits'] + 1;
setcookie('visits', $visits, time() + 3600 * 24 * 365);
?>
<!DOCTYPE html>
<html lang="it">
<head><title>Cart</title>
<style>
table {
border-collapse: collapse;
}
td, th {
border: 1px solid black;
}
</style>
</head>
<body>
<h1>Your cart</h1>
<?php global $visits;
if($visits > 1) {
echo "<h2>Welcome back!! Visit number: $visits</h2>";
}
else echo "<h2>Welcome! This is your first visit!</h2>";
?>
<?php if(count($cart)>0): ?>
<p>Your cart contains <?php echo count($cart); ?> items.</p>
<p>Total: <?php echo number_format($total, 2); ?></p>
<table border="1">
<thead>
<tr>
<th>Item Name</th>
<th>Item Desc</th>
<th>Item Category</th>
<th>Price</th>
<th>Options</th>
</tr>
</thead>
<tfoot>
<tr>
<td>Tot:</td>
<td><?php echo number_format($total, 2); ?></td>
</tr>
</tfoot>
<tbody>
<?php foreach($cart as $item): ?>
<tr>
<td><?php echo $item['name']; ?></td>
<td><?php echo $item['desc']; ?></td>
<td><?php echo $item['category']; ?></td>
<td>$<?php echo number_format($item['price'], 2); ?></td>
<td><form action="?del" method="post">
<div>
<input type="hidden" name="delid" id="delid" value="<?php echo $item['id']; ?>">
<input type="submit" name="del" id="del" value="Delete">
</div>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<p><a href=".">Return back to our catalog!</a></p>
<form action="?" method="post">
<p><a href="?paypal">Continue shopping</a> or <input type="submit" name="action" id="action" value="Empty Cart"></p>
</form>
<?php else: ?>
<p>Your cart is empty! You can buy from our <a href=".">catalog</a></p>
<?php endif; ?>
</body>
</html>
Этот скрипт на этом сайте: http://hydrerscript.altervista.org/
Простыми словами, мой тестовый сайт, где я загрузить все мои скрипты (PHP, JQuery и другие ...)
Во всяком случае, в чем проблема?
Ну, проблема, которая, когда мы удаляем элемент, «Удалить» кнопку, система удаления только те элементы, которые являются дубликатами, трехкратном повторе (и так далее ..) из других ..
Простой пример:
Вы можете попробовать купить и положить в корзину 8 предметов, 2 конана, 2 моего гарриного гончара, 2 гончара Гарри и камень философа и 2 гончара-гончара, затем перейдите, чтобы посмотреть вашу корзину.
Это будет изображение показало:
Img ->http://dumpshare.net/images/1765764stackoverflow.PNG < - Img
Затем попытайтесь TGO в корзину и для каждого пунктов нажмите кнопку 'Удалить'.
Как вы можете видеть, система не удалять только до 4-х пунктов, потому что, как я уже писал, удаляются только те элементы, которые являются дубликатами, трехкратном повторе и так дальше, из других ..
Почему?
Как решить это