Jump to content

Get $_POST values within loop


petenaylor

Recommended Posts

Hi all

I am trying to write a piece of code that grabs post values. The form looks like this:

 

Menus  <input name="tagid" value="1" type="hidden" />
<input name="portfolioid" value="8" type="hidden" />
<input name="check_1" type="checkbox" value="1"  />

 

Basically there will be a variable number of tick boxes. I need to grab the values that have the checkbox value of 1 and insert them into a mySQL database.

 

I am already grabbing some other data from the form. How do I assign the input_name to a string in a loop?

 

Many thanks

 

Pete

 

Link to comment
https://forums.phpfreaks.com/topic/265952-get-_post-values-within-loop/
Share on other sites

I would Do this:

Menus  <input name="tagid" value="1" type="hidden" />

<input name="portfolioids[]" type="checkbox" value="8"  />

 

And I believe a non checked box won't even pass in the $_POST, so you'll have an array called $_POST['portfolioids'] that contains all the values you checked. Then use an insert statement. There are many posts on here with examples of multiple inserts in one statement.

Thanks for your help.

 

I have now done print_r($_POST['portfolioids']);

 

Which gives me :

 

Array ( [19] => 8 [7] => 8 [8] => 8 [18] => 8 [20] => 8 [14] => 8 [9] => 8 [11] => 8 )

 

as I only ticked these boxes. I now need to write a loop to add these into my mySQL database. Can I do a for each on just these post values?

 

 

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.