-1

I am trying to notify the user for their expired products. This works well. but i am not being able to display the product name in alert which is the variable $product->name.

   <?php foreach($productsofuser as $product):?>
        <?php if($product->status="Expired")
            {
                ?><script>alert('Product expired!');</script><?php
            }
        ?>
    <?php endforeach;?>
Steve
  • 1,622
  • 5
  • 21
  • 39

2 Answers2

1

Use echo

<?php foreach($productsofuser as $product):?>
        <?php if($product->status="Expired")
            {
               echo"<script>alert('Product expired!');</script>";
            }
        ?>
    <?php endforeach;?>
muya.dev
  • 966
  • 1
  • 13
  • 34
1

Just add the product name to the string:

  <?php foreach($productsofuser as $product):?>
        <?php if($product->status="Expired")
            {
                ?><script>alert('Product <?php echo $product->name; ?> expired!');</script><?php
            }
        ?>
    <?php endforeach;?>
Ben Hillier
  • 2,126
  • 1
  • 10
  • 15