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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:07:50+00:00 2026-06-08T20:07:50+00:00

First off I know this is a duplicate question that is asked on here

  • 0

First off I know this is a duplicate question that is asked on here fairly often, however I have perused through those answers and still can’t figure out what is wrong with my code. I am fairly new to PHP, and I am 99% sure this is a very easy/novice thing to accomplish, which is why it’s frustrating me.

Here is the code:

    $validProgram = 0;
$validProgramCodes = array('ITFZ', 'ITFC', 'ITFP', 'ITFE', 'ITFL', 'ITFS',
                           'ITFF', 'ITFM', 'ITFT', 'IEME', 'ISMK', 'IPKT');

if ( isset( $_GET[ 'category' ] ) && isset( $_GET[ 'subcategory' ] )
    && $_GET[ 'category' ] != '' && $_GET[ 'subcategory' ] != '' )
{
    $selectedSchool = $_GET[ 'category' ];
    $selectedProgram = $_GET[ 'subcategory' ];
    $selectedSchool = prepString( $selectedSchool );
    $selectedProgram = prepString( $selectedProgram );

    foreach ( $validProgramCodes as $temp )
    {
        if ( $temp == $selectedProgram )
        {
            $validProgram ++;
        }
    }

    if ( $validProgram == 1 )
    {
        echo "success!";
    }
    else if ( $validProgram !== 1)
    {
        echo "failure!";
    } 
}

}

Now… for some reason, no matter what is supplied for $selectedProgram, the validation check echos out the failurestatement. This is really simple code so I’m sure it’s something glaringly obvious, but I think I just need another pair of eyes to give it a quick glance over. 🙂

Thank you for any help!

  • 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-08T20:07:52+00:00Added an answer on June 8, 2026 at 8:07 pm

    if ( $validProgram = 1 ) assigns the value 1 to $validProgram. This assignment returns 1, so the statement always passes.

    Try if ( $validProgram == 1 ) to test for equality.

    Regardless, looking at the whole block, it looks like you compress a lot of this down to a single in_array check, removing the foreach loop and the $validProgram variable entirely:

    $selectedProgram = prepString( $selectedProgram );
    
    if(in_array($selectedProgram, $validProgramCodes))
    {
        echo "success!";
    }
    else
    {
        echo "failure!";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, I know that this question begs the other question - should the
First off: I know that this isn't reliable for actually checking if I can
Ok... First off, I know this isn't a new question. But, for some reason
I know first off that this is probably the worst looking regex ever but
First off, let me preface this question by stating that I'm really a pretty
First off, let me start by saying, I know this exact question has been
First off I'm not sure that's the proper title for this question but hopefully
First off, before I ask, i would like to point out that this question
First off, I'm embarassed that I don't know this. I know these things work,
First off, I know this may be a very stupid question, so don't shoot

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.