Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select MySQL records to update with checkbox

Status
Not open for further replies.

bcreigh

Technical User
Joined
Sep 21, 2002
Messages
3
Location
US
I need to be able to select which records will be passed to a query. I have designed a page that displays all of the records from a table and at the end of each line, I have placed a checkbox. I want to be able to pass only the records that have a check in the box to the update query.

I guess the real question is can I pass an array to either post or get or as a session variable.

Any ideas will be greatly appreciated.

Bob
 
Yes, you can pass an array to $_POST or $_GET.

If your form element names take the appearance of a PHP array reference, they will appear in a single array in $_POST or $_GET.

For example, this form:

<form method=&quot;POST&quot; action=&quot;foo.php&quot;>
<input type=&quot;checkbox&quot; name=&quot;check[1]&quot;>
<input type=&quot;checkbox&quot; name=&quot;check[2]&quot;>
<input type=&quot;checkbox&quot; name=&quot;check[3]&quot;>
</form>

when submitted, $_POST['check'] will itself be an array containing indeces and values only for those checkboxes that were selected.

If you use the record IDs from your table in the place of 1, 2, 3 in my example, then the indeces of $_POST['check'] will contain the table record IDs of those records that should be manipulated.

Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top