FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Notice: Undefined index: action error please help
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Notice: Undefined index: action error please help [message #175394 is a reply to message #175393] Wed, 14 September 2011 01:10 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 9/13/2011 4:51 PM, Konstantinos wrote:
> Hello,
> i have and index.php file which i have a menu and i want to unclude
> some others file in it, using some parameteres passed from the url.
> But i am getting an error "Notice: Undefined index: action.... in line
> etc"
>
> Heres my code:
> ...
> <div class="menu">
> <ul>
> <li><a href="index.php">Home</a></li>
> <li><a href="index.php?action=store">Store</a></li>
> <li><a href="index.php?action=profile">Profile</a></li>
> </ul>
> </div>
> ...
>
> in another line inside the same index.php file i have:
> ...
> <?php
> if ($_GET['action']=="profile")
> include("profile.php");
> else if ($_GET['action']=="store")
> include("store.php");
> else if ($_GET['action']=="login")
> include("user_login_form.php");
> else
> echo "Welcome screen";
>
> ?>
> ...
>
> When i am in the home address i get an error "Notice: Undefined index:
> action" for all 3 lines i use $_GET['action']. When i click on the
> other links eg store or profile the include is being done
> successfully.
>
> What am i doing wrong??
>
> Thanks in advance
> Kostas

Your entire PHP script is executed and terminates before the page is
displayed on the browser. So the first time though, $_GET['action']
doesn't exist. When someone clicks on a link, then the action parameter
is passed to the script and $_GET['action'] has a value.

Any time you're expecting something from the browser you should check to
see if it has been set with isset(), i.e.

if (isset($_GET['action'])) ...

And only try to process the parameter if it has been set.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Previous Topic: Social Bookmarks Script
Next Topic: date parsing
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 02:09:19 GMT 2024

Total time taken to generate the page: 0.04809 seconds