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
Share on other sites

So you have a couple of checkboxes on the first page that each hold an array,eg array(2, 5, 7) for checkbox 2. Then on the second page, after a user has chosen checkbox 2, you want a button for each of these values in the array. Is that what you want?

Link to comment
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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.