1
votes

I'm trying to make a button so when the users -> user_id == the same as the products-> user_id echo a button but its not working. So only when the product has the same user_id as the session user_id , I want to echo a button with a link to another page but its not working.

This is what I tried to do:

<div class="cadeau_bewerken">
        <?php if ( $_SESSION['user_id'] ==  $product["user_id"]): ?>
    <a class="btn btn-primary" href="<?php echo base_url() ?>/KdGwController/details_bewerken/<?php echo $product->product_id; ?>"> Cadeau bewerken </a>
<?php endif; ?>
    </div>

I do see a button but its not a link and not working and I'm getting this error:

A PHP ERROR WAS ENCOUNTERED
Severity: Notice
Message: Trying to get property of non-object
Filename: views/details.php
Line number: 54

This is line number 54 in details.php:

<a class="btn btn-primary" href="<?php echo base_url() ?>/KdGwController/details_bewerken/<?php echo $product->product_id; ?>"> Cadeau bewerken </a>

And yes I defined $product because on the same page I'm able to echo the name for example like this:

<?php echo $product['product_name']; ?>
4
Please post your modal function. - NikuNj Rathod
$product is array or object. Nothing both. In your example it's an array. - pavel
There is no model function that belongs to this code.. I'm trying to echo a button on the view page when the session user_id is the same as product user_id - Learningprogrammingphp44

4 Answers

2
votes

in your code you use $product->product_id this is the way to address objects while your $product is an array.

2
votes
<div class="cadeau_bewerken">
        <?php if ( $_SESSION['user_id'] ==  $product["user_id"]): ?>
    <a class="btn btn-primary" href="<?php echo base_url() ?>/KdGwController/details_bewerken/<?php echo $product->product_id; ?>"> Cadeau bewerken </a>
<?php endif; ?>
    </div>

In condition you use $product["user_id"] as an array, but in link, as an object. The error says, that it can't get product_id property from your variable. I assume, that you should use $product['product_id']instead of $product->product_id.

1
votes

Your $product variable is array not object so you need to chnage your code as below:

<a class="btn btn-primary" href="<?php echo base_url() ?>/KdGwController/details_bewerken/<?php echo $product['product_id]; ?>"> Cadeau bewerken </a>
1
votes

I think your $product variable is not an object. You can check with this

var_dump($product)

and this should work

<a class="btn btn-primary" href="<?php echo base_url() ?>/KdGwController/details_bewerken/<?php echo $product['product_id']; ?>"> Cadeau bewerken </a>