Inserting all 0's or all 1's into database
<p>I have the following code, which almost works:</p>

<pre><code>&lt;?php
    if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
        $fields = array(
            'col1'  =&gt; 'cb1', 
            'col2'  =&gt; 'cb2', 
            'col3'  =&gt; 'cb3', 
            'col4'  =&gt; 'cb4', 
            'col5'  =&gt; 'cb5',
            'col6'  =&gt; 'cb6', 
            'col7'  =&gt; 'cb7', 
            'col8'  =&gt; 'cb8', 
            'col9'  =&gt; 'cb9', 
            'col10' =&gt; 'cb10'
        );

        $parts = array();

        foreach( $fields as $dbfield =&gt; $field ) {
            $parts[] = '`' . $dbfield . '` = :' . $dbfield;
        }

        $dbh = new PDO( 'mysql:host=localhost;dbname=database', 'user', 'pass' );
        $dbh -&gt; setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

        $sth = $dbh -&gt; prepare( 'UPDATE `table1` SET ' . join( ', ', $parts ) . ' WHERE `id` = :id' );

        // temp simulation value
        $id = 1;

        $sth -&gt; bindParam( ':id', $id, PDO::PARAM_INT, 4 );

        foreach( $fields as $dbfield =&gt; $field ) {

            $value = isset( $_POST[$field] ) ? 1 : 0;
            $sth -&gt; bindParam( ':' . $dbfield, $value, PDO::PARAM_INT, 4 );

        }

        $sth -&gt; execute();

        $dbh = null;
    }
?&gt;

&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;&lt;/title&gt;
    &lt;/head&gt;

    &lt;body&gt;
        &lt;form method="post"&gt;

            &lt;input type="checkbox" name="cb1" /&gt;&lt;br /&gt;

            &lt;input type="checkbox" name="cb2" /&gt;&lt;br /&gt;

            &lt;input type="checkbox" name="cb3" /&gt;&lt;br /&gt;

            &lt;input type="checkbox" name="cb4" /&gt;&lt;br /&gt;

            &lt;input type="checkbox" name="cb5" /&gt;&lt;br /&gt;

            &lt;input type="checkbox" name="cb6" /&gt;&lt;br /&gt;

            &lt;input type="checkbox" name="cb7" /&gt;&lt;br /&gt;

            &lt;input type="checkbox" name="cb8" /&gt;&lt;br /&gt;

            &lt;input type="checkbox" name="cb9" /&gt;&lt;br /&gt;

            &lt;input type="checkbox" name="cb10" /&gt;

            &lt;input type="submit" value="save" /&gt;

        &lt;/form&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>It should be inserting 0's or 1's depending on the checkbox selected, but for some reason it inserts 0's into all columns no matter which checkboxes are selected.  However, if the last checkbox is selected, it inserts a 1 into all columns.</p>
