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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:14:34+00:00 2026-06-10T19:14:34+00:00

I would like a new item to be added to an array if a

  • 0

I would like a new item to be added to an array if a button is pressed

This is my code…

$engineers = array();

if(isset($_POST['add_user'])){
    $engineers[] = $_POST['engineer'];
    $array_count = count($engineers);
}

All it does is replace the only item in the array rather than add to it, where am I going wrong?

Thanks

The form used is

$dropdown = '<select id="engineer" name="engineer" class="select_engineer" type="text" name="engineer" /><option>Select Diary</option>';
while($row = mysql_fetch_assoc($result)){
    $dropdown .= "\r\n<option value='{$row['user_name']}'>{$row['user_name']}</option>";
}
$dropdown .= "\r\n</select>";

“>

(The list of engineers is populated from a MySQL database).

There isn’t anywhere else that adds to the array, I just want a button that will add the engineers user name to the array

  • 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-10T19:14:35+00:00Added an answer on June 10, 2026 at 7:14 pm

    your array resets every time you reload the page.
    you have to store the data in cookies or sessions or database or …
    simple idea :

    <?php
    session_start();
    if(!isset($_SESSION['engineers']))
    $engineers = array();
    else
    $engineers = unserialize($_SESSION['engineers']);
    if(isset($_POST['add_user'])){
        $engineers[] = $_POST['engineer'];
        $array_count = count($engineers);
    }
    $_SESSION['engineers'] = serialize($engineers);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a web-based logviewer using extjs. I would like new log-lines to
PHP/MySQL (CodeIgniter) I would like to add new interest_keywords in the exist database value.
I would like to load a new extension in a symfony2 project for twig
I would like to create a new controller that will allow the admin user
I would like to open a new aspx page when i click on a
I would like to create a 'New Document' dialog similar to the Office 2007
i would like to buy a new cell phone that runs Android. From what
I would like to set the new child documents to default to a set
I would like to insert a new DataGridViewRow into my DataGridView at a specific
I would like to use the new migration feature of EF, but on my

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.