Jump to content

Notice: Undefined index - Probably something simple someone can help me resolve!


chet139

Recommended Posts

Hi All,

 

I am getting the following notice/warning

 

 

Notice: Undefined index: action in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\cart.php on line 8

 

The code it relates to is this I understand its because the action clause as nothing passed to it from the posting - as thats only when I get the warning. See extract of relevent code below from cart.php:

 

	switch($_GET["action"])
{
	case "add_item":
	{
		AddItem($_GET["id"], $_GET["qty"]);
		ShowCart();
		break;
	}
	case "update_item":
	{
		UpdateItem($_GET["id"], $_GET["qty"]);
		ShowCart();
		break;
	}
	case "remove_item":
	{
		RemoveItem($_GET["id"]);
		ShowCart();
		break;
	}
	default:
	{
		ShowCart();
	}
}

 

 

Posting page extract code below

<font face="verdana" size="1" color="black">
<a href="cart.php?action=add_item&id=<?php echo $row["productId"]; ?>&qty=1">Add Item</a>
</font>

Link to comment
Share on other sites

* sorry didnt completely read your post, but ill leave what i said

 

the GET parameter "action" isn't passed. you can shut this notice off in the php config i believe, or you can do this...

 

isset($_GET['action'])

 

if you test for that first before you reference it, you should be good without those notices

Link to comment
Share on other sites

could just wrap the following 'if' statement around the switch

 

<?php
if(isset($_GET["action"])){
switch($_GET["action"])
{
	case "add_item":
	{
		AddItem($_GET["id"], $_GET["qty"]);
		ShowCart();
		break;
	}
	case "update_item":
	{
		UpdateItem($_GET["id"], $_GET["qty"]);
		ShowCart();
		break;
	}
	case "remove_item":
	{
		RemoveItem($_GET["id"]);
		ShowCart();
		break;
	}
	default:
	{
		ShowCart();
	}
}
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.