Database query failed: Column count doesn't match value count at row 1
<p>What is with this error? </p>

<p>I am trying to upload a file and i get that error : Database query failed: Column count doesn't match value count at row 1! </p>

<pre><code>protected static $table_name= "images";


    protected static $db_fields = array('id', 'filename', 'type', 'size', 'caption');

        public $id;
        public $filename;
        public $type;
        public $size;
        public $caption;

        private $temp_path;
        protected $upload_dir = "images";
        public $errors=array();
</code></pre>

<p>and the save function:</p>

<pre><code>public function save()
    {
        if(isset($this-&gt;id))
        {
            $this-&gt;update();
        }
        else
        {
            if(!empty($this-&gt;errors))
            {
                return false;
            }
            if(strlen($this-&gt;caption) &gt; 255)
            {
                $this-&gt;errors[] = "The caption can only be 255 characters long.";
                return false;
            }
            if(empty($this-&gt;filename) || empty($this-&gt;temp_path))
            {
                $this-&gt;errors[] = "The file location was not available";
                return false;
            }

            $target_path = SITE_ROOT .DS. 'public' .DS. $this-&gt;upload_dir .DS.$this-&gt;filename;  

            if(file_exists($target_path))
            {
                $this-&gt;errors[] = "The file {$this-&gt;filename} already exists.";
                return false;
            }
            if(move_uploaded_file($this-&gt;temp_path, $target_path))
            {
                    if( $this-&gt;create() )
                    {
                        unset($this-&gt;temp_path);
                        return true;
                    }
            }
            else
            {
                $this-&gt;errors[] = "The file upload failed, possibly due to incorrect permissions on the upload folder.";
                return false;
            }   
        }   
    }
</code></pre>

<p>plus the create function</p>

<pre><code>public function create()
    {
        global $database;
        $attributes = $this-&gt;sanitized_attributes();
        $sql = "INSERT INTO ".self::$table_name."(";
        $sql .= join(", ", array_keys($attributes));
        $sql .= ") VALUES ('";
        $sql .= join(", ", array_values($attributes));
        $sql .= "')";

        if($database-&gt;query($sql))
        {
            $this-&gt;id = $database-&gt;insert_id();
            return true;
        }
        else
        {
            return false;
        }
    } 
</code></pre>

<p>i have another one that takes the values </p>

<pre><code>protected function sanitized_attributes()
    {
        global $database;
        $clean_attributes = array();

        foreach($this-&gt;attributes() as $key =&gt; $value)
        {
            $clean_attributes[$key] = $database-&gt;escape_value($value);
        }
        return $clean_attributes;   
    }
</code></pre>

<p>how can i resolve the error? <strong>Database query failed: Column count doesn't match value count at row 1</strong></p>
