Jump to content

Undefined Index problem


aarbrouk

Recommended Posts

Hi,

 

I am fairly new to php and seem to be getting this common error...

 

"Notice: Undefined index: action in C:\wamp\www\Veetees\cart\cart.php on line 8"

 

When clicking on a link on one php page, to take me to a page called cart.php it shows this error message.

 

The script it is trying to run is:

 

<?php

session_start();

 

require "../connect.php";

 

$cart = $_SESSION['cart'];

$action = $_GET['action'];

 

Seems to not like the $action variable but I don't understand what undefined index means?? any help would be appreciated...

 

Many thanks.

Link to comment
https://forums.phpfreaks.com/topic/148919-undefined-index-problem/
Share on other sites

The index is the key with which you access an element in an array. In your case of $_GET['action'] you are trying to retrieve the index called action on the array called $_GET.

 

In your case that index doesn't exist and you'll get a notice from PHP. You can use isset or key_exists to check this.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.