dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: Column count doesn't match value count at row 1 Error

  1. #1
    Join Date
    Sep 2012
    Posts
    6

    Exclamation Column count doesn't match value count at row 1 Error

    Hi,

    i am trying to store some values into a database, but upon trying to add i am getting a "Column count doesn't match value count at row 1"

    i believe i am passing something incorrectly but was hoping someone could point me in the right direction

    i have included my code here




    many thanks

  2. #2
    Join Date
    Nov 2006
    Location
    Oakland
    Posts
    500
    You certainly do not have the correct number of field data in the first row of your query.
    It maybe because you have a misplaced comma or quote somewhere.

    If you need an extra pair of eyes then paste your query for us to see.
    Please double check, and you'll discover you were missing something.

  3. #3
    Join Date
    Sep 2012
    Posts
    6
    thanks for the reply

    my code is here > http://pastebin.com/JTrXc23V

  4. #4
    Join Date
    Nov 2006
    Location
    Oakland
    Posts
    500
    You did not indicate how many fields your database table has. So there is no way to make the column count comparison just by looking at your code.
    There is an excessive use of single quotes in your query that forces you to add escape slashes and makes your code hard to read.

    You have a syntax error at time () . ('

    How about for instance:

    $sql="INSERT INTO $dblist VALUES(
    '0',
    '".$_POST['userid']."',
    '".$_POST['location']."',
    '".$row['type']."',
    '".time ()."',
    '".time ()."',
    '".$expire."',
    '".$row['expire']."'
    '0',
    '0',
    '".$_POST['hide']."',
    '".$_POST['featured']."',
    '".$_POST['status']."'",
    '1',
    '".$_POST['stock']."',
    '".$_POST['vin']."',
    '".$_POST['model_year']."',
    '".$_POST['make']."',
    '".$_POST['model']."',
    '".$_POST['cond']."',
    '".$_POST['category']."',
    '".$_POST['category2']."',
    '".$_POST['mileage']."',
    '".$_POST['mileage_alt']."',
    '".$_POST['price']."',
    '".$_POST['sale']."',
    '".$_POST['price_alt']."',
    '".$_POST['exterior']."',
    '".$_POST['interior']."',
    '".$_POST['doors']."',
    '".$_POST['fuel']."',
    '".$_POST['drive']."',
    '".$_POST['engine']."',
    '".$_POST['trans']."',
    '".$_POST['top_speed']."',
    '".$_POST['horsepower']."',
    '".$_POST['torque']."',
    '".$_POST['towing']."',
    '".$_POST['features']."',
    '".$_POST['description']."',
    '".$_POST['tagline']."',
    '".$_POST['link_url']."',
    '".$_POST['link_text']."',
    '".$_POST['ebay_url']."')";

    if (!(mysql_query($sql, $link))){ exit (mysql_error ()); }

    You also need to use the addslashes() function to all submitted data to prevent SQL injection (e.g addslashes($_POST['engine']) )

    By using the $sql variable is provide and comparing the number of fields with the column count of your table you should be able to easily spot the errors.
    Always write your code with simplicity and readability in mind.

  5. #5
    Join Date
    Sep 2012
    Posts
    6
    Thanks for replying

    i have 49 fields in my database (listed below)

    id
    userid
    location
    user_type
    added
    updated
    expire
    user_expire
    viewed
    images
    hide
    featured
    status
    pending
    stock
    vin
    model_year
    make
    model
    cond
    category
    category2
    mileage
    mileage_alt
    price
    sale
    price_alt
    mot
    mot_expire
    reg_plate
    reg_docs
    owners
    exterior
    interior
    doors
    fuel
    drive
    engine
    trans
    top_speed
    horsepower
    torque
    towing
    features
    description
    tagline
    link_url
    link_text
    ebay_url

    i have since removed the incorrect syntax

    so the code now reads

    \'' . time () . '\',

    unfortunately this gives me a blank white page

    if i get this fixed i will then make a start at improving my code
    Last edited by nzz; 09-10-2012 at 07:36 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles