Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to include a variable inside of a post variable within a query string? -php
    text
    copied!<p>I have a table with a lot of checkboxes. The checkboxes are being produced via a loop, and are given a unique id. </p> <pre><code>$get_depts = mysql_query("select dept_id, dept_name from depts where bus_id = '{$business['bus_id']}'"); while(($department = mysql_fetch_assoc($get_depts))) { echo '&lt;tr&gt;&lt;td&gt;'.$department['dept_name'].'&lt;/td&gt;'; $req_fields = mysql_fetch_assoc(mysql_query("SELECT employees, department, customer, salespeople, acct_nbrs, categories, subcategories, case_ids, login_ids, phone, phext, cust_email, problem, resolution, source, priority FROM required_fields WHERE dept_id = '{$department['dept_id']}'")); if($req_fields['employees'] == 'YES'){echo '&lt;td&gt;&lt;input type="checkbox" id="employees[]" name="employees[]" value="YES" checked&gt;&lt;/td&gt;';} else echo'&lt;td&gt;&lt;input type="checkbox" id="employees[]" name="employees[]" value="YES"&gt;&lt;/td&gt;'; } </code></pre> <p>As you can see, one such example of the id and name of a checkbox is employees1, employees2, etc.</p> <p>After submit, I try and loop back through my departments to pick up the unique id numbers again. Then I try and update my table.</p> <pre><code>$get_depts = mysql_query("select dept_id, dept_name from depts where bus_id = '{$business['bus_id']}'"); while(($department = mysql_fetch_assoc($get_depts))) { mysql_query("Update required_fields set employees = '{$_POST['employees'.$department['dept_id']]}' where dept_id = '{$department['dept_id']"); } </code></pre> <p>I obviously am not using the correct syntax for the post variable. How can I correctly use $_POST['employees'] + $department['dept_id']?</p> <p><em><strong>EDIT</em></strong></p> <p>The <strong>FINAL</strong> result would look like this. If $department['dept_id'] = 10 for example, then the name of the post variable would be $_POST['employees10']</p>
 

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