Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP MySQL - update multiple rows at one time
    primarykey
    data
    text
    <p>I have a form that is displaying data that is pulled from a database. There are several columns that are being pulled for the form. The basic structure of the form looks like this:</p> <pre><code>&lt;form&gt; &lt;input type="checkbox" name="check" value="$value" checked="$valueCheck" /&gt; $label - $editedBy @ $editedDate &lt;input type="checkbox" name="check" value="$value" checked="$valueCheck" /&gt; $label - $editedBy @ $editedDate &lt;input type="checkbox" name="check" value="$value" checked="$valueCheck" /&gt; $label - $editedBy @ $editedDate &lt;input type="checkbox" name="check" value="$value" checked="$valueCheck" /&gt; $label - $editedBy @ $editedDate &lt;input type="checkbox" name="check" value="$value" checked="$valueCheck" /&gt; $label - $editedBy @ $editedDate &lt;input type="submit" name="update" value="Update Checklist" /&gt; &lt;/form&gt; </code></pre> <p>The variables are all populated dynamically when the pages loads from data in the database. Here is my question...each input and corresponding data is being pulled from a single row in a "checklist" table. So, in the example above you would be looking at data from 5 rows in the database. When i check off a box and click submit i want it to submit that checked box to the database as a value of true or false depending on whether or not the box is checked or unchecked. I know how to do all that if i was only submitting one row; however, i am not sure how to do this with the multiple rows. I'm assuming i'll have to use some type of loop with my <code>UPDATE</code> query.</p> <p>What would be the best way to accomplish this? Thanks for any help! Let me know if you have any questions at all. Sorry if doesn't explain my situation well enough.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COA few things you might want to let us know, what is $value and what does it equal? Also, you need to put a name attribute in these checkboxes so you can reference them. Additionally, you need to add an action and method attribute to your form tag so that it knows where to process the information and in which way.
      singulars
    2. COAs linus72982 said: "Also, you need to put a name attribute in these checkboxes so you can reference them." The `name` attribute would be most important to allow you to tie back the form input back to your intended database record. Names and values of form inputs are the only things that get passed back to PHP (excluding files). You could of course name each input in the form of an array (see: http://php.net/manual/en/language.variables.external.php) ...
      singulars
    3. COThanks guys...however, i do have all the correct form attributes in the actual form...i just didn't put them in the example as they are not needed for this example. And yes the input fields have name attributes as well. I'll update the example code to reflect the names that i have $value equals either true or false depending on whether or not the box is checked or unchecked. I'm more so wanting to figure out the posting portion of this form...not the form itself. I'm just passing the values to post.php which will post the values to the database.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload