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>

* 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

I sort of get where you are going with this. But with reference to my cart.php code supplied, what changes are exactly required.

 

i tried switch isset ($_GET["action"])

 

but i dont think the syntax i gave is correct.

 

Im a newbie!

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();
	}
}
}
?>

better rather....

 

set a variable to capture the GET var first, if it is set use it, otherwise set it to nothing...

<?php
$your_var = (isset($_GET["action"]))?$_GET["action"]:'';
?>

 

then use ...

<?php
switch($your_var)
?>

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.