خرید بک لینک
As per title, I have a problem when adding products to the cart: it would show a window message that says that the product has been added, but in truth it is not there. It gives the following error: Fatal error: Caot use object of type stdClass as array .

La linea di codice e': <td><?php echo $value['item_name']; ?></td>

Here is the code file reserve.php :
PHP Code:

 <?php
  
  session_start
();
  
ini_set('display_errors'1);
  
$coect mysqli_coect('127.0.0.1''root''***********''Community Garden List');
  
  
  if (isset(
$_POST['add'])) {
    if (isset(
$_SESSION['cart'])) {
        
$item_array_id array_column($_SESSION['cart'], 'product_id');
        if (!
in_array($_GET['id'], $item_array_id)) {
            
$count count($_SESSION['cart']);
            
$item_array = array(
                
'product_id' => $_GET['id'],
                
'item_name' => $_POST['hidden_name'],
                
'product_price' => $_POST['hidden_price'],
                
'item_quantity' => $_POST['quantity'],
            );
            
$_SESSION['cart'][$count] = $item_array;
            echo 
'<script>window.location="reserve.php"</script>';
        } else {
            echo 
'<script>alert("Product is already Added to Cart")</script>';
            echo 
'<script>window.location="reserve.php"</script>';
        }
    } else {
        
$item_array = array(
            
'product_id' => $_GET['id'],
            
'item_name' => $_POST['hidden_name'],
            
'product_price' => $_POST['hidden_price'],
            
'item_quantity' => $_POST['quantity'],
        );
        
$_SESSION['cart'][0] = $item_array;
    }
 }
 
 if (isset(
$_GET['action'])) {
    if (
$_GET['action'] == 'delete') {
        foreach (
$_SESSION['cart'] as $keys => $value) {
            if (
$value['product_id'] == $_GET['id']) {
                unset(
$_SESSION['cart'][$keys]);
                echo 
'<script>alert("Product has been Removed...!")</script>';
                echo 
'<script>window.location="reserve.php"</script>';
            }
        }
    }
 }
 
?>
 
    ?>

html code

PHP Code:

<?php
  
     $query 
'SELECT * FROM product ORDER BY serial ASC';
     
$result mysqli_query($coect$query);
  
     if (
mysqli_num_rows($result) > 0) {
         while (
$row mysqli_fetch_array($result)) {
             
?>
             <div class="col-md-4">
            <form method="post" action="reserve.php?action=add&id='.$row['id'].">
            <div style="border: 1px solid #eaeaec; margin: -1px 19px 3px -1px; box-shadow: 0 1px 2px rgba(0,0,0,0.05); padding:10px;" align="center">
 
                <img src="<?php echo $row['image']; ?>" class="img-responsive" style="width:100%;>
            <h5 class="text-info"><?php echo $row['pname']; ?></h5>
            <h5 class="text-danger">x80 <?php echo $row['price']; ?></h5>
            <h5 class="text-info"><?php echo $row['pdescription']; ?></h5>
            <input type="text" name="quantity" class="form-control" value="1">
            <input type="hidden" name="hidden_name" value="<?php echo $row['pname']; ?>">
            <input type="hidden" name="hidden_price" value="<?php echo $row['price']; ?>">
            <input type="hidden" name="hidden_pdescription" value="<?php echo $row['pdescription']; ?>">
            <input type="submit" name="add" style="margin-top:5px;" class="btn btn-success" value="Add to Bag">
            </div>
            </form>
            </div>
            <?php
 
        
}

I've tried print "<pre>"; var_dump($row); exit; after this line: foreach e($_SESSION['cart'] as $key => $value) { and it comes a table with NULL inside. What does that mean?

Before that, i tried to change $value['item_name'] with $value->item_name , and i got the following error:
Notice: Undefined property: stdClass::$item_name in

Will you please help me to understand what's wrong?thank you.

برچسب: نویسنده: آیلین رضوانی تاريخ: سه شنبه 19 دی 1396 ساعت: 17:24

صفحه بندی