Jump to content

Archived

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

cturner

Column count doesn't match value count at row 1

Recommended Posts

I am getting the following error when I test the code that is below:
Could not add the entry because: Column count doesn't match value count at row 1. The query was INSERT INTO `tbl_product` (`id`, `category`, `productname`, `description`, `bullet1`, `bullet2`, `bullet3`, `bullet4`, `bullet5`, `bullet6`, `extrainfo1`, `packsize1`, `packsize2`, `price1`, `colour1`, `colour2`, `colour3`, `colour4`, `colour5`, `icon1`, `icon2`, `icon3`, `icon4`, `extrainfo2`, `mainphoto`, `imagefile1`, `imagefile2`, `imagefile3`, `imagefile4`, `nameprint`, `address`) VALUES ('0', '', 'Vinyl Stickers', 'This (and the Magic-Iron on label) are THE basic items of your back to school pack. Try to do without them and you risk loosing your brand new kit, or worse still your child coming home with someone elses mankey old shoes. Don’t say you haven’t been warned!', '', '', '', '', 'bullet5', '', '', '50 labels', '100 labels', 'AU$20.00', 'AU$33.00', 'red', 'green', 'pink', 'orange', 'blue', 'heart', 'train', 'flower', 'football', '', '', '', '', '', '', '', '').
I am trying to add data to a database. Can someone please tell me why I am getting that error and how I can fix it? Thanks in advance.
[code]
require "config.php";
// the add button
if (isset($_POST['add'])) {
$arrErrors = array();
// get information in the text boxes
$selectCategory = mysql_real_escape_string($_POST['selectCategory']);
$productname = mysql_real_escape_string($_POST['productname']);
$description = mysql_real_escape_string($_POST['description']);
$bullet1 = mysql_real_escape_string($_POST['bullet1']);
$bullet2 = mysql_real_escape_string($_POST['bullet2']);
$bullet3 = mysql_real_escape_string($_POST['bullet3']);
$bullet4 = mysql_real_escape_string($_POST['bullet4']);
$bullet5 = mysql_real_escape_string($_POST['bullet5']);
$bullet6 = mysql_real_escape_string($_POST['bullet6']);
$extrainfo1 = mysql_real_escape_string($_POST['extrainfo1']);
$packsize1 = mysql_real_escape_string($_POST['packsize1']);
$packsize2 = mysql_real_escape_string($_POST['packsize2']);
$price1 = mysql_real_escape_string($_POST['price1']);
$price2 = mysql_real_escape_string($_POST['price2']);
$colour1 = mysql_real_escape_string($_POST['colour1']);
$colour2 = mysql_real_escape_string($_POST['colour2']);
$colour3 = mysql_real_escape_string($_POST['colour3']);
$colour4 = mysql_real_escape_string($_POST['colour4']);
$colour5 = mysql_real_escape_string($_POST['colour5']);
$icon1 = mysql_real_escape_string($_POST['icon1']);
$icon2 = mysql_real_escape_string($_POST['icon2']);
$icon3 = mysql_real_escape_string($_POST['icon3']);
$icon4 = mysql_real_escape_string($_POST['icon4']);
$extrainfo2 = mysql_real_escape_string($_POST['extrainfo2']);
$mainphoto = mysql_real_escape_string($_POST['mainphoto']);
$imagefile1 = mysql_real_escape_string($_POST['imagefile1']);
$nameprint = mysql_real_escape_string($_POST['nameprint']);
$address = mysql_real_escape_string($_POST['address']);

if ($_POST ['selectCategory'] == 'none') {
$arrErrors['selectCategory'] = 'Please select a category name.';
}
if ($_POST ['productname'] == '') {
$arrErrors['productname'] = 'Please enter a product name.';
}
if ($_POST ['description'] == '') {
$arrErrors['description'] = 'Please enter a description for the product.';
}
if ($_POST ['price1'] == '') {
$arrErrors['price1'] = 'Please enter a price for the product.';
}
// validate the main photo field


// check to see if the product exists
$sql = mysql_query("SELECT * FROM `tbl_product` WHERE `productname`='$productname'");

$check = mysql_num_rows($sql);

if ($check != 0) {
$arrErrors['productname'] = 'The product already exists.';
}

if (count($arrErrors) == 0) {
$result = "INSERT INTO `tbl_product` (`id`, `category`, `productname`, `description`, `bullet1`, `bullet2`, `bullet3`, `bullet4`, `bullet5`, `bullet6`, `extrainfo1`, `packsize1`, `packsize2`, `price1`, `colour1`, `colour2`, `colour3`, `colour4`, `colour5`, `icon1`, `icon2`, `icon3`, `icon4`, `extrainfo2`, `mainphoto`, `imagefile1`, `imagefile2`, `imagefile3`, `imagefile4`, `nameprint`, `address`) VALUES ('0', '$category', '$productname', '$description', '$bullet1', '$bullet2', '$bullet3', '$bullet4', 'bullet5', '$bullet6', '$extrainfo1', '$packsize1', '$packsize2', '$price1', '$price2', '$colour1', '$colour2', '$colour3', '$colour4', '$colour5', '$icon1', '$icon2', '$icon3', '$icon4', '$extrainfo2', '$mainphoto', '$imagefile1', '$imagefile2', '$imagefile3', '$imagefile4', '$nameprint', '$address')";
if (mysql_query($result)) {
header ('Location: product_added.php');
} else {
print "<p>Could not add the entry because: <b>" . mysql_error() . "</b>. The query was $result.</p>";
}
} else {
// The error array had something in it. There was an error.
        // Start adding error text to an error string.
        $strError = '<div class="formerror"><p>Please check the following and try again:</p><ul>';
        // Get each error and add it to the error string
        // as a list item.
        foreach ($arrErrors as $error) {
            $strError .= "<li>$error</li>";
        }
        $strError .= '</ul></div>';
}
}
[/code]

Share this post


Link to post
Share on other sites
You have specified 31 column names and 32 values to put into them.  Either you missed a column or you added an extra value.  The error message just means that the number of column names and number of values don't match.

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.