のためにユーザに警告をポップアップ表示されますときたぶん、あなたが変更する必要があります:
<?php
$product = array(
'id' => $_GET['id'],
'name' => $_GET['name'],
'price' => $_GET['price'],
);
$_SESSION['product'] = $product;
?>
<h1>Shopping Cart</h1><br>
<table border=1>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Price</th>
</tr>
</thead>
<tbody id="tb">
<?php if isset($_SESSION['product']): ?>
<tr>
<td><?php echo $_SESSION['product']['id']; ?></td>
<td><?php echo $_SESSION['product']['name']; ?></td>
<td><?php echo $_SESSION['product']['price']; ?></td>
</tr>
<?php endif; ?>
</tbody>
</table>
アプリで複数の商品をサポートする必要がある場合:
<?php
// you can check that the cart exists, if not, create it.
if (!isset($_SESSION['cart']){
$_SESSION['cart'] = array(
'products' => array(),
);
}
$product = array(
'id' => $_GET['id'],
'name' => $_GET['name'],
'price' => $_GET['price'],
);
//add 1 product to your cart
$_SESSION['cart']['products'][] = $product;
?>
<h1>Shopping Cart</h1><br>
<table border=1>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Price</th>
</tr>
</thead>
<tbody id="tb">
<?php if isset($_SESSION['cart']): ?>
//$product is only 1 product in the cart
<?php foreach ($_SESSION['cart']['products'] as $product): ?>
<tr>
<td><?php echo $product['id']; ?></td>
<td><?php echo $product['name']; ?></td>
<td><?php echo $product['price']; ?></td>
</tr>
<?php else: ?>
<tr>
<td>No products</td>
</tr>
<?php endif; ?>
</tr>
</tbody>
</table>
「私の3つのセッション」はどういう意味ですか? – SebCar
$ _SESSION ['id'] [] = $ _GET ['id'];$ _SESSION ['name'] [] = $ _GET ['name']; $ _ SESSION ['価格'] [] = $ _GET ['価格']; – NTM
私はその情報を他の人に移したいと思っています.... – NTM