By Perad on
This is my error
user warning: Column count doesn't match value count at row 1 query: INSERT INTO portfolio (nid, image_small, image) VALUES (8, 8, '', '') in /Applications/xampp/xamppfiles/htdocs/drupal/includes/database.mysql.inc on line 172.
This is my code, I am sure that the problem is either with the form api or the sql insert. Could someone give this a look over and tell me where my problem lies.
<?php
// $Id$
/**
* @file
* Provides a "joke" node type.
*/
/**
* Implementation of hook_node_info().
*/
function portfolio_node_info() {
// We return an array since a module can define multiple node types.
// We're only defining one node type, type 'joke'.
return array(
'portfolio' => array(
'name' => t('Portfolio'), // Required.
'module' => 'portfolio', // Required.
'description' => t('Add a portfolio item!'), // Required.
'has_title' => TRUE,
'title_label' => t('Title'),
'has_body' => TRUE,
'body_label' => t('Portfolio'),
'locked' => TRUE
)
);
}
/**
* Implementation of hook_menu().
*/
function portfolio_menu($may_cache) {
$items = array();
// Do not cache this menu item during the development of this module.
if (!$may_cache) {
$items[] = array(
'path' => 'node/add/portfolio',
'title' => t('Portfolio'),
'access' => user_access('create portfolio'),
);
}
return $items;
}
/**
* Implementation of hook_perm().
*/
function portfolio_perm() {
return array('create portfolio', 'edit own portfolio');
}
/**
* Implementation of hook_access().
*/
function portfolio_access($op, $node) {
global $user;
if ($op == 'create') {
return (user_access('create portfolio'));
}
if ($op == 'update' || $op == 'delete') {
return (user_access('edit own portfolio') && ($user->uid == $node->uid));
}
}
/**
* Implementation of hook_form().
*/
function portfolio_form($node) {
// Get metadata for this node type
// (we use it for labeling title and body fields).
// We defined this in joke_node_info().
$type = node_get_types('type', $node);
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -5
);
$form['body_filter']['body'] = array(
'#type' => 'textarea',
'#title' => check_plain($type->body_label),
'#default_value' => $node->body,
'#rows' => 7,
'#required' => TRUE
);
$form['body_filter']['filter'] = filter_form($node->format);
$form['picture']['image_small'] = array(
'#type' => 'file',
'#title' => t('Upload Teaser Picture'),
'#size' => 48,
'#description' => t('Your virtual face or picture.')
);
$form['picture']['image'] = array(
'#type' => 'file',
'#title' => t('Upload Main Image'),
'#size' => 48,
'#description' => t('Your virtual face or picture.')
);
return $form;
}
/**
* Implementation of hook_validate().
*/
function portfolio_validate($node) {
// Enforce a minimum word length of 3.
}
/**
* Implementation of hook_insert().
*/
function portfolio_insert($node) {
db_query("INSERT INTO {portfolio} (nid, image_small, image) VALUES (%d, %d, '%s', '%s')",
$node->nid, $node->vid, $node->image_small, $node->image);
}
/**
* Implementation of hook_update().
*/
function portfolio_update($node) {
if ($node->revision) {
portfolio_insert($node);
}
else {
db_query("UPDATE {portfolio} SET image_small = '%s', image = '%s' WHERE vid = %d",
$node->image_small, $node->image, $node->vid);
}
}
/**
* Implementation of hook_delete().
*/
function portfolio_delete(&$node) {
// Delete the related information we were saving for this node.
db_query('DELETE FROM {portfolio} WHERE nid = %d', $node->nid);
}
/**
* Implementation of hook_load().
*/
function portfolio_load($node) {
return db_fetch_object(db_query('SELECT image_small, image FROM {portfolio} WHERE vid = %d',
$node->vid));
}
/**
* Implementation of hook_view().
*/
function portfolio_view($node, $teaser = FALSE, $page = FALSE) {
if (!$teaser) {
// Use Drupal's default node view.
$node = node_prepare($node, $teaser);
// Now add the punchline.
// $node->content['image_small'] = array(
// '#value' => theme('portfolio', $node),
// '#weight' => 2
// );
}
if ($teaser) {
// Use Drupal's default node view.
$node = node_prepare($node, $teaser);
}
return $node;
}
Comments
Can anyone help? The file
Can anyone help?
The file isn't uploading, is the form at least correct?