Jump to content


Photo

*SOLVED* Inserting multiple records


  • Please log in to reply
1 reply to this topic

#1 bcamp1973

bcamp1973
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 07 April 2006 - 06:48 PM

I have a list like this....


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


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


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');
                }
            }
        }
    }
}



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


Invalid argument supplied for foreach()


what am i missing?

#2 bcamp1973

bcamp1973
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 07 April 2006 - 06:59 PM

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

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

not this

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users