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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:38:30+00:00 2026-06-08T15:38:30+00:00

So I have this basic html form. My goal is to pass the values

  • 0

So I have this basic html form. My goal is to pass the values submitted to this form into a mysql table.

 <form action="?action=settings" method="post">
      <ul>
        <li>
           <label for="settingValue[1]">Setting 1:</label>
           <input type="text" name="settingValue[1]" id="setting1" required />
        </li>
        <li>
            <label for="settingValue[2]">Setting 2:</label><br>
            <input checked type="radio" name="settingValue[2]" value="1" />On<br>
            <input type="radio" name="settingValue[2]" value="0" />Off
         </li>
         <li>
             <input type="submit" name="saveChanges" value="Save Changes" />
         </li>
       </ul>
   </form>

My mysql table has only 3 columns (id, settingName, settingValue)
So I want to update multiple records in my table using this form (In this case rows 1 and 2) by storing the value into the “settingValue” column.

After some research I found that what seems to be the best way to do this would be by posting an array (Which is what I attempted to do above), then use a foreach loop to to run through the array and update the table.

I guess my main problem is figuring out how to use the array. Because I need to UPDATE a record NOT create a new one. I also need to retain the ID so I can update the corresponding record.

After hours of googling my best guess was to do this:

if ( isset( $_POST['saveChanges'])) {
    foreach($_POST['settingValue'] as $key => $settingValue )  {
        $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
        $conn->exec("UPDATE settings SET settingValue=$settingValue WHERE id=$key");
        $conn = null;
    }

But it is yielding no results.

  • 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-08T15:38:35+00:00Added an answer on June 8, 2026 at 3:38 pm

    Keep $settingValue and $key in quotes:

    $conn->exec("UPDATE settings SET settingValue='$settingValue' WHERE id='$key'");
    

    Tip: Keep $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); outside the foreach loop. No need to repeat the connection on each loop

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a basic html/css question... I have a simple one-button form that
I have a basic HTML form that gets inserted into a server side div
I have a js.erb with this basic content: $(#currencies).html(<%= options_for_select([['Dollar', '$']])%>); And the html
I have this table, which can be seen as a basic custom gantt chart:
I have a basic html form that adds some data to the page using
Summary : This is a basic, stand alone web form. Just html form, with
I have a basic html form which I want to use with two submit
I have an html form which inserts data into a database. I just built
I have an AJAX call which dynamically generates a HTML form. This form contains
I have a basic HTML form that I am centering. I am using jQuery

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.