Jump to content

Code Snippet Anybody Please? Checkbox Array from MySQL! I'm really desperate!


eits

Recommended Posts

Hi, I have a page called page 1 with checkboxes on it. The value of each checkbox is

<?php echo $row_rsquotes['item_id']; ?>

. Using a loop I fetch each record from a MySQL database and so each checkbox should have the item_id as a value if it is checked.

 

Could anybody give me an example of code I could put on the page which the form posts to in order to get each item_id and echo them?

 

I would be really greatful!!!

Link to comment
Share on other sites

Provided you named your checkbox's using an array. eg;

 

<input type="checkbox" name="cb[]" value="<?php echo $row_rsquotes['item_id']; ?>"

 

Then to simply echo the checkboxes that where checked on the recieving page...

 

<?php

 if (isset($_POST['submit'])) {
   foreach($_POST['cb'] as $checked) {
     echo $checked . "<br />";
   }
 }

?>

 

Does this help?

Link to comment
Share on other sites

Provided you named your checkbox's using an array. eg;

 

<input type="checkbox" name="cb[]" value="<?php echo $row_rsquotes['item_id']; ?>"

 

Then to simply echo the checkboxes that where checked on the recieving page...

 

<?php

  if (isset($_POST['submit'])) {
    foreach($_POST['cb'] as $checked) {
      echo $checked . "<br />";
    }
  }

?>

 

Does this help?

 

 

This worked great. Thanks!!!!

Link to comment
Share on other sites

OK! I'm trying to get the selected boxes (which I can now do). However from the item_id I want to be able to move all matching fields from table 1 to table 2 in mysql.

 

Currently I have:

"INSERT IGNORE INTO orders (item_quant, item_type, item_desc, quote_id, comp_id, description) SELECT (item_quant, item_type, item_desc, quote_id, comp_id, description) FROM quote"

 

Which is in the loop.

 

But it doesn't work :( I keep getting Operand should contain 1 column(s)

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.