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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:42:13+00:00 2026-05-26T19:42:13+00:00

Multiple posts but I’m still stuck…I’m missing something fundamental here. I have a form

  • 0

Multiple posts but I’m still stuck…I’m missing something fundamental here. I have a form with a select:

<select name="camera_status[]">
  <option <?php echo $enabled_option; ?>>Enabled</option>
  <option <?php echo $disabled_option; ?>>Disabled</option>
</select>

This form is built with a loop to give a list of all camera settings. So you would have multiple cameras and their corresponding camera_status. Also I have a hidden input field with the camera_id:

The camera_id is processed with some javascript. Then I process that with:

$camera_id = $_POST['camera_id'];

if (is_array($_POST['camera_status']))
{
  foreach ($_POST['camera_status'] as $camera_status) {
    $query_status = 'UPDATE `#__cameras` SET `camera_status` ="'.$camera_status.'" WHERE `camera_id`='.$camera_id;
    $db->setQuery($query_status);
    $db->query();
  }
}

If I echo the camera_id it is correct. But my foreach runs an update query for the full list of cameras instead of just the one selected. So it updates only the last camera in the list. Let me know if it makes sense to update the full code. Obviously I’m going about this all wrong…

  • 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-05-26T19:42:14+00:00Added an answer on May 26, 2026 at 7:42 pm

    EDIT: Well if you have single selection then it is simpler than that:

    HTML:

    <select name="camera_status">
      <option value="Enabled">Enabled</option>
      <option value="Disabled">Disabled</option>
    </select>
    

    And PHP:

    $camera_id = (int) $_POST['camera_id']; //Here you had SQL injection.
    $camera_status = mysql_real_escape_string($_POST['camera_status']); //Neither that was protected.
    
    $query_status = 'UPDATE `#__cameras` SET `camera_status` ="'.$camera_status.'" WHERE `camera_id`='.$camera_id;
    $db->setQuery($query_status);
    $db->query();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form page that posts to another page where multiple fields as
I've been reading multiple posts on here about htaccess folder rewriting but none seem
I've already asked something about link_to here : Multiple posts handled by links and
There are multiple posts on here that capture value , but I'm just looking
I have a page with multiple forms that I submit via Ajax POSTs serially.
I am trying to send the same parameter name with multiple values, but even
I have multiple hidden form fields which store values about the the current view
First time poster, long time lurker :) I have a form setup that posts
I've read multiple posts on this but it's not working properly for me. I'm
I have two tables: posts and custom_fields. A post can have multiple custom_fields. Posts

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.