Jump to content

Archived

This topic is now archived and is closed to further replies.

bcamp1973

*SOLVED* Inserting multiple records

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?

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.