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

Link to comment
Share on other sites

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?

 

 

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.