Jump to content

Checkbox array and PHP/MySQL Help!


tjg73

Recommended Posts

Here is my problem.  Basically the process is this:  When a user clicks on a checkbox on page 1 that holds the array of id numbers, a separate browser window opens  up (page 2)prompting them to click a button.  When that button is clicked I want to update mySQL table based on the id number that was checked from that checkbox on page one.  Did that make sense?  So really I am not sure how to get that id checkbox value and put it into a variable so I can use it on page 2.  Can anyone please help!!!!

 

Thanks

tjg

Link to comment
https://forums.phpfreaks.com/topic/81981-checkbox-array-and-phpmysql-help/
Share on other sites

There are a few checkboxes on page 1.  It is one array of records out of the db.  The checkbox's value is the id field of the db.  That value when the checkbox is clicked has to go across to page 2 where there is a button that when clicked changes a column in the table simply from a "No" to a "Yes" based on that id value.  Was that a little more clear?

Here is a quick and dirty one:

 

checkboxes:

<?php
// I assume you are echoing them with a while statement, you should have initiated a form as well posting the values on to another page

while (// your expression) {
echo "<input type='checkbox' name='yourname[]' value='$array[checked]'>";
}
?>

 

process the values

<?php
$yourname = $_POST['yourname'];

foreach ($yourname as $key => $value) {
mysql_query("UPDATE `table` SET `field`='yes' WHERE `id`='$value'");
}
?>

 

Edit that, make it more secure, etc.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.