Complication de code dans la creation de shopping cart
jeanlohata
Messages postés
1
Statut
Membre
-
jordane45 Messages postés 40050 Statut Modérateur -
jordane45 Messages postés 40050 Statut Modérateur -
je veux creer un shopping mais le browser n'arrive pas a trouver mon array et il m'envois ce message
Notice: Undefined index: item_name in C:\xampp\htdocs\Ecommerce_master\index.php on line 166
Notice: Undefined index: item_quantity in C:\xampp\htdocs\Ecommerce_master\index.php on line 167
Notice: Undefined index: item_price in C:\xampp\htdocs\Ecommerce_master\index.php on line 168
Notice: Undefined index: item_quantity in C:\xampp\htdocs\Ecommerce_master\index.php on line 169
il
voici mes codes
EDIT : Ajout des balises de code
Notice: Undefined index: item_name in C:\xampp\htdocs\Ecommerce_master\index.php on line 166
Notice: Undefined index: item_quantity in C:\xampp\htdocs\Ecommerce_master\index.php on line 167
Notice: Undefined index: item_price in C:\xampp\htdocs\Ecommerce_master\index.php on line 168
Notice: Undefined index: item_quantity in C:\xampp\htdocs\Ecommerce_master\index.php on line 169
il
voici mes codes
<?php
session_start();
$connect = mysqli_connect("localhost", "root", "", "manage_articles");
if(isset($_POST["add_to_cart"]))
{
if(isset($_SESSION["shopping _cart"]))
{
$item_array_id = array_column($_SESSION["shopping_cart"], "item_id");
if(!in_array($_GET["id"], $item_array_id))
{
$count = count($_SESSION["shopping_cart"]);
$item_array = array(
'item_id' => $_GET["id"],
'item_name' => $_POST["hidden_name"],
'item_price' => $_POST["hidden_price"],
'item_quantity' => $_POST["quantity"]
);
$_SESSION["shopping_cart"][$count] = $item_array;
}
else
{
echo "<script> alert('Item Already added'); </script>";
echo "<script> window.location'index.php' </script>";
}
}
else
{
$item_array = array(
'$item_id' => $_GET["id"],
'$item_name' => $_POST["hidden_name"],
'$item_price' => $_POST["hidden_price"],
'$item_quantity' => $_POST["quantity"]
);
$_SESSION["shopping_cart"][0] = $item_array;
}
}
//===================================
<?php
$query = "SELECT * FROM tbl_product ORDER BY id ASC";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
?>
<div class="col-md-3">
<form method="post" action="index.php?action=add&id=<?php echo $row["id"]; ?>">
<div id="espace_product">
<img src="<?php echo $row["img"]; ?>" class="img-responsive"><br>
<h4 class="text-info"><?php echo $row["name"]; ?></h4>
<h4 class="text-danger">$<?php echo $row["price"]; ?></h4>
<input type="text" name="quantity" class="form-control" value="1" />
<input type="hidden" name="hidden_name" value="<?php echo $row["name"]; ?>" />
<input type="hidden" name="hidden_price" value="<?php echo $row["price"]; ?>" />
<input type="submit" name="add_to_cart" style="margin-top:5px;" class="btn btn-danger" value="Add to Card" />
</div>
</form>
</div>
<?php
}
}
?>
//======================================================
<tr>
<th width="40%"> Item Name</th>
<th width="10%"> Quatity</th>
<th width="20%"> Price</th>
<th width="15%"> Total</th>
<th width="5%"> Action</th>
</tr>
<?php
if(!empty($_SESSION["shopping_cart"]))
{
$total = 0;
foreach($_SESSION["shopping_cart"] as $keys => $values)
{
?>
<tr>
<td><?php echo $values["item_name"]; ?></td>
<td><?php echo $values["item_quantity"]; ?></td>
<td>$ <?php echo $values["item_price"]; ?></td>
<td><?php echo number_format($values["item_quantity"] * $values["item_price"], 2); ?></td>
<td> <a href="index.php?action=delete&id=<?php echo $values["item_id"]; ?>"><span class="text-danger">Remove</a></span></td>
</tr>
<?php
$total = $total + ($values["item_quantity"] * $values["item_price"]);
}
?>
<tr>
<td colspan="3" align="right">Total</td>
<td align="right">$ <?php echo number_format($total, 2); ?></td>
<td></td>
</tr>
<?php
EDIT : Ajout des balises de code
A voir également:
- Complication de code dans la creation de shopping cart
- Code ascii - Guide
- Code de déverrouillage oublié - Guide
- Creation de site web - Guide
- Creation de compte google - Guide
- Création de compte gmail - Guide
1 réponse
Bonjour,
A quelles lignes de code correspondent les lignes 166 , 167 ,168 ?
As tu bien un session start sur chaque page ?
Je te conseille, pour la gestion du panier en SESSION d'utiliser ceci :
https://codes-sources.commentcamarche.net/source/102874-php-panier-caddi-virtuel-en-session
A quelles lignes de code correspondent les lignes 166 , 167 ,168 ?
As tu bien un session start sur chaque page ?
Je te conseille, pour la gestion du panier en SESSION d'utiliser ceci :
https://codes-sources.commentcamarche.net/source/102874-php-panier-caddi-virtuel-en-session