Fix Notice: Undefined index


I added this to my pages but it gives errors “Notice: Undefined index kw” on every page load.

How can I fix it?

<?php if ($_GET['kw']): ?>
<?php echo ucwords($_GET['kw']); ?>
<?php else: ?>
<?php echo $_helper->productAttribute($_product, $_product->getHeadline(), 'headline') ?>
<?php endif; ?>

Thank you

What does $_GET contain?

Not sure what $_GET contains. It gets the kw URL Parameters if they are there.


var_dump it before your if.

If I add this <?php echo var_dump($_GET['kw']); ?> before it without any URL Parameters it returns NULL

That’s not the way to use var_dump. You don’t echo it, you just call it see the manual and was suggesting dumping the entire $_GET array - we already know $_GET['kw'] doesn’t exist.

In any event, you need to look at where you think you set $_GET['kw'] as it is not getting set.

Try this:

<?php if ( isset($_GET['kw']) && $_GET['kw']) : ?>



if ( if ( isset($_GET['kw']) && $_GET['kw'])  :
  $tmp = ucwords($_GET['kw']); 
  $tmp = $_helper->productAttribute($_product, $_product->getHeadline(), 'headline') ;
echo '<h1>' .$tmp .'</h1>';

I changed it to:

<?php if (isset($_GET['kw'])): ?>
<?php echo ucwords($_GET['kw']); ?>
<?php else: ?>
<?php echo $_helper->productAttribute($_product, $_product->getHeadline(), 'headline') ?>
<?php endif; ?>

It seems to work fine without errors this way.

1 Like

You know you don’t need an opening <?php and closing ?> tag on every line, don’t you? One opening tag at the beginning and a closing one at the end will be enough.


Yes, but I understand it a little better. : )

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.