Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7937325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:29:53+00:00 2026-06-03T22:29:53+00:00

index.php contains links in this style: <a href=index.php?id=1>1</a> <a href=index.php?id=2>2</a> and then a PHP

  • 0

index.php contains links in this style:

<a href="index.php?id=1">1</a>
<a href="index.php?id=2">2</a>

and then a PHP passage in this style:

if ($_GET["id"] == "1") {}
elseif ($_GET["id"] == "2") {}

So when a link is clicked, the page is reloaded, and one of the if/elseif blocks is run.

However, when I load index.php the first time I get this error: Undefined index: id

I guess this means that $_GET["id"] needs to have a default value. But where do I put this default value in my code? If I give it, for example, the value "0" in the beginning of the script, the code blocks will never run, since the value keeps being reset on every reload.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:29:54+00:00Added an answer on June 3, 2026 at 10:29 pm

    You can first check to see if it has been set:

    if (isset($_GET["id"])) {
    
        if ($_GET["id"] == "1") {
    
        } elseif ($_GET["id"] == "2") {
    
        }
    
    }
    

    isset is a language construct which will not issue any errors if the variable isn’t set.

    empty also won’t issue errors but also checks for a “non-empty” value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page index.php where i have a link called add_users.php. In add_users.php,
I pass a variable to domain.com/index.php?user=username In my page (index.php) contains others pages like
My website has a structure like this: root folder contains --- > 1)index.php 2)
I've just had an argument with a colleaque. My index.php contains my mysql connection
how can i redirect index.php?search= to the base url? I tried it with this
I'm trying to make a request to a website this way : file_get_contents('http://www.yahoo.com/index.php?var=value'); in
Okay, here is my situation. I have a page, index.php, which is the mainsite
This is the code I'm using (it's the index.php file) /* Set an include
I have this little php snippet: // $test='test'; $test='just a test'; echo <a href=javascript:myfunction($number,$src_req,\.$test.\)><img
I am working with a custom MVC PHP framework and the index page (acting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.