Jump to content

*SOLVED* Inserting multiple records


bcamp1973

Recommended Posts

I have a list like this....

[code]

<ul>
<li><input type="checkbox" name="sku" value="257" />whatever</li>
<li><input type="checkbox" name="sku" value="271" />something</li>
<li><input type="checkbox" name="sku" value="272" />bla</li>
</ul>

[/code]

then i have the following code to submit whatever checked in the list along with a few other fields

[code]

if(isset($_POST['submit'])) {
    reqForm('name');
    reqForm('brand_id','brand');
    if($formSubmit) {
        @mysql_query(
        "UPDATE collections SET ".
        "name = '{$_POST['name']}', ".
        "department = '{$_POST['department']}', ".
        "brand_id = '{$_POST['brand_id']}' ".
        "WHERE id = '{$_GET['collectionid']}'"
        ) OR mkQueryError('UPDATE DETAILS');

        if($_POST['sku']) {
            foreach($_POST['sku'] as $sku) {
                if($sku !== '') {
                    @mysql_query("INSERT INTO collection_skus (collection_id,sku_id) VALUES ('{$_GET['collectionid']}',$sku)") OR mkQueryError('ADD SKUS');
                } else {
                    @mysql_query("DELETE FROM collection_skus WHERE collection_id = '{$_GET['collectionid']}' AND sku_id = $sku") OR mkQueryError('REMOVE SKUS');
                }
            }
        }
    }
}


[/code]

so far all i get is the following error...

[code]

Invalid argument supplied for foreach()

[/code]

what am i missing?
Link to comment
Share on other sites

i solved it....i'm an idiot...it's becuase the list needs to look like this...

[code]
<li><input type="checkbox" name="sku[]" value="257" />whatever</li>
[/code]

not this

[code]
<li><input type="checkbox" name="sku" value="257" />whatever</li>
[/code]
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.