SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: MySQL error

  1. #1
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL error

    I am getting an error when trying to insert data into my table. Here is the error:
    Column count doesn't match value count at row 1

    Here is the query:
    PHP Code:
    $query "INSERT INTO companies (name, 
                                         type, 
                                         language, 
                                         contact, 
                                         address, 
                                         telephone, 
                                         mobile, 
                                         email, 
                                         website, 
                                         date_setup, 
                                         intro) 
                                         
                                VALUES ('
    {$_POST['name']}', 
                                        '
    {$_POST['type']}', 
                                        '
    {$_POST['language']}'
                                        '
    {$_POST['contact']}', 
                                        '
    {$_POST['address']}', 
                                        '
    {$_POST['telephone']}', 
                                        '
    {$_POST['mobile']}', 
                                        '
    {$_POST['email']}', 
                                        '
    {$_POST['website']}',
                                        '
    {$time}',
                                        '
    {$_POST['intro']}'                 
                                        )"

    And this is what I used to create the table:
    PHP Code:
    mysql_query('CREATE TABLE companies (
    ID int(15) unsigned NOT NULL AUTO_INCREMENT,
    name VARCHAR(35),
    type VARCHAR(35),
    language VARCHAR(35),
    contact VARCHAR(35),
    address VARCHAR(50),
    telephone VARCHAR(35),
    mobile VARCHAR(15),
    email VARCHAR(50),
    website VARCHAR(50),
    date_setup VARCHAR(15),
    intro VARCHAR(15),
    PRIMARY KEY (ID),
    UNIQUE (name),
    INDEX (type)
    );'

    or die 
    Thanks in advance for any help!

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    'type' is a MySQL Reserved Word. I'd just rename that column (though you could `backquote` it if you like).

  3. #3
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I deleted the table and started afresh. I have named that column company_name, but nothing else has been changed.

    I tried it with the following query but still get the exact same error.
    PHP Code:
        $query "INSERT INTO companies (`name`, 
                                         `company_type`, 
                                         `language`, 
                                         `contact`, 
                                         `address`, 
                                         `telephone`, 
                                         `mobile`, 
                                         `email`, 
                                         `website`, 
                                         `date_setup`, 
                                         `intro`) 
                                         
                                VALUES ('
    {$_POST['name']}', 
                                        '
    {$_POST['company_type']}', 
                                        '
    {$_POST['language']}'
                                        '
    {$_POST['contact']}', 
                                        '
    {$_POST['address']}', 
                                        '
    {$_POST['telephone']}', 
                                        '
    {$_POST['mobile']}', 
                                        '
    {$_POST['email']}', 
                                        '
    {$_POST['website']}',
                                        '
    {$time}',
                                        '
    {$_POST['intro']}'                 
                                        )"


  4. #4
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    '{$_POST['company_type']}',
    '{$_POST['language']}' <-- missing the ,
    '{$_POST['contact']}',

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    comma missing after '{$_POST['language']}'

    this would have been a *lot* easier to spot if you had adopted the "leading comma" sql formatting style --
    Code:
    INSERT 
      INTO companies 
         ( `name`
         , `company_type`
         , `language`
         , `contact`
         , `address`
         , `telephone`
         , `mobile`
         , `email`
         , `website`
         , `date_setup`
         , `intro` ) 
    VALUES 
         ( '{$_POST['name']}'
         , '{$_POST['company_type']}'
         , '{$_POST['language']}' 
           '{$_POST['contact']}'
         , '{$_POST['address']}'
         , '{$_POST['telephone']}'
         , '{$_POST['mobile']}'
         , '{$_POST['email']}'
         , '{$_POST['website']}'
         , '{$time}'
         , '{$_POST['intro']}' )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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