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 7854985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:14:58+00:00 2026-06-02T20:14:58+00:00

if ((!$_GET[‘month’]) && (!$_GET[‘year’])) { $month = date (n); $year = date (Y); }

  • 0
if ((!$_GET['month']) && (!$_GET['year'])) {
  $month = date ("n");
  $year = date ("Y");
} else {
  $month = $_GET['month'];
  $year = $_GET['year'];
}

it shows Notice: Undefined index: month in.... .

I know that if I use error_reporting(null); above the code, the notice will not appear, but is there a way to fix this error?

  • 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-02T20:14:59+00:00Added an answer on June 2, 2026 at 8:14 pm

    If the array element does not exist, you get the notice since you are trying to access a non-existent element. You need to use isset() or empty() to check it (those are not functions but language constructs so it’s not considered accessing those elements). Since you probably never have empty/zero years/months, empty makes more sense; but you could also use !isset(), then 0 and empty strings will be allowed, too.

    if(empty($_GET['month']) || empty($_GET['year'])) {
        $month = date('n');
        $year = date('Y');
    }
    else {
        $month = (int)$_GET['month'];
        $year = (int)$_GET['year'];
    }
    

    However, it might make more sense to check those two variables separately:

    $month = empty($_GET['month']) ? date('n') : $_GET['month'];
    $year = empty($_GET['year']) ? date('Y') : $_GET['year'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Get month of a given date which is stored in a PHP time variable
.get() converts a jQuery object to a DOM element that Javascript can use without
//get choice input int n; scanf (%d,&n); // print the option that the user
I downloaded PostgreSQL from the official website and ran the .dmg installer. After that
Get this simple python code, same matching with re.compile instance. I noticed that even
I am doing a simple coin flipping experiment for class that involves flipping a
Get data week-wise my mysql since jan-2011. Timestamp is unix time stamp.so that i
Get a problem when installing java application as service in windows environment(Win 7). use
get_class() will give me the eventual class of an object. I want to know
Get User Action [HttpGet] [ActionName(Index)] public ActionResult Get(int id) { User u = UserCore.GetUser(id);

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.