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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:16:15+00:00 2026-06-15T02:16:15+00:00

$min_year = 1; $max_year = 10; $years = range($min_year, $max_year); // returns array with

  • 0
$min_year = 1;
$max_year = 10;
$years = range($min_year, $max_year); // returns array with numeric values of 1900 - 2012
$yearHTML = '';
$yearHTML .= '<select name="year" id="yearDrop">'.PHP_EOL; 
$yearHTML .= '<option value="">Please Select</option>'.PHP_EOL;  
foreach ($years as $year) {
    if (!$validSubmission && isset($_POST['year']) && $year == $_POST['year'])
    {
        $yearHTML .= "<option value='".$year."' selected='selected'>$year</option>".PHP_EOL;
    }
    else
    {
        $yearHTML .= "<option value='".$year."'>$year</option>".PHP_EOL;
    }
}

$yearHTML .= '</select>'; 

Above I have a drop down menu which consists of options 1 – 10 in the drop down menu. The problem I am having is that no matter which number I select from the drop down menu, it keeps inserting the number 1 in the database. Can anybody see why in the code below why it is doing this:

$getyear = in_array($_POST['year'], $years);

    $insertsql = "
    INSERT INTO Student
    (Year)
    VALUES
    (?)
    ";
    if (!$insert = $mysqli->prepare($insertsql)) {
    // Handle errors with prepare operation here
    }                                           

    $insert->bind_param("i", $getyear);

    $insert->execute();

    if ($insert->errno) {
    // Handle query error here
    }

    $insert->close();
  • 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-15T02:16:16+00:00Added an answer on June 15, 2026 at 2:16 am
    $getyear = in_array($_POST['year'], $years);
    

    returns TRUE. True is cast to INT, so becomes 1;

    Replace by:

    if( in_array($_POST['year'], $years) === true ){
      $getyear = (int) $_POST['year'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with the following structure: ID, Month, Year, Value with values
I need to group by range of years starting from date of birth. This
I have a rather large query which select data from a certain date range.
For this query SELECT min(date) min_date FROM order_products group by order_id min_date ignores the
I'm trying to render sliders instead of select components. Each page has several select
Any help is greatly appreciated. I have a table hospital: Nurse + Year +
I have the following validator for the year of birth: <f:validateLongRange minimum=1920 maximum=1992 />
I have a SQL2008 table of automotive makes, models, and year. To display a
What I'm trying to do is to check if the year of the date
I'm trying to perform calculations, apply conditions for the calculated values and count results

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.