chet139 Posted February 23, 2008 Share Posted February 23, 2008 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> Quote Link to comment Share on other sites More sharing options...
fooDigi Posted February 23, 2008 Share Posted February 23, 2008 * 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 Quote Link to comment Share on other sites More sharing options...
chet139 Posted February 23, 2008 Author Share Posted February 23, 2008 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! Quote Link to comment Share on other sites More sharing options...
chet139 Posted February 23, 2008 Author Share Posted February 23, 2008 Anyone? I just need to know how to stop that notice.. Thanks again (sorry for the repost - dont one this getting buried) Quote Link to comment Share on other sites More sharing options...
fooDigi Posted February 23, 2008 Share Posted February 23, 2008 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(); } } } ?> Quote Link to comment Share on other sites More sharing options...
fooDigi Posted February 23, 2008 Share Posted February 23, 2008 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) ?> Quote Link to comment Share on other sites More sharing options...
chet139 Posted February 23, 2008 Author Share Posted February 23, 2008 Thanks for your help. I wrapped the SWITCH around the IF isset and then ELSE for the other thing to do. Works exactly how I want it. This can be marked as solved if appropriate option is available? Quote Link to comment Share on other sites More sharing options...
revraz Posted February 23, 2008 Share Posted February 23, 2008 Used to be, maybe they'll figure out how to bring it back some day. This can be marked as solved if appropriate option is available? Quote Link to comment Share on other sites More sharing options...
chet139 Posted February 23, 2008 Author Share Posted February 23, 2008 Ok cool! LOL Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.