www.webdeveloper.com
Results 1 to 3 of 3

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

  1. #1
    Join Date
    Nov 2007
    Posts
    1

    Column count doesn't match value count at row 1

    With this cone above, I got this error.
    Can anyone help me?

    <?php

    $longitude = '-47.894317';
    $latitude = '-15,7366566';
    $timestamp = '1367349998375';

    $mysql_id = mysql_connect('127.0.0.1', 'root', '') or die(mysql_error());
    mysql_select_db('dbLocation', $mysql_id) or die(mysql_error());

    # Insert a row of information into the table "example"

    mysql_query("INSERT INTO tbLocation( longitude, latitude, timestamp ) VALUES ($longitude, $latitude, $timestamp)") or die(mysql_error());


    if($query)
    {
    echo "Data Inserted!";
    $resultArr[0]['result'] = ˝true˝;
    }
    else
    {
    echo mysql_error();
    $resultArr[0]['result'] = ˝false˝;
    }

    mysql_close($mysql_id);

    ?>

    Thank's in advance

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,614
    Try this format so you can see exactly what got submitted to the DB:
    PHP Code:
    $sql "
    INSERT INTO tbLocation(
      longitude,
      latitude,
      timestamp
    ) VALUES (
      
    $longitude,
      
    $latitude,
      
    $timestamp
    )"
    ;
    mysql_query($sql) or die("<pre>\n".mysql_error()."\n$sql</pre>"); 
    PS: I suspect you're going to have to quote those values as strings, plus you should always sanitize your values, so...
    PHP Code:
    $sql "
    INSERT INTO tbLocation(
      longitude,
      latitude,
      timestamp
    ) VALUES (
      '"
    .mysql_real_escape_string($longitude)."',
      '"
    .mysql_real_escape_string($latitude)."',
      '"
    .mysql_real_escape_string($timestamp)."'
    )"
    ;
    mysql_query($sql) or die("<pre>\n".mysql_error()."\n$sql</pre>"); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    May 2013
    Location
    London, UK
    Posts
    16
    NogDog's solution will fix your problem. The reason this error occurs is because you've defined three field names to insert into (longitude, latitude, timestamp) but SQL only thinks you've provided one value, although to you you've provided three. SQL thinks this because you haven't added quotes around the values like in NogDog's example. The error appears when the field count does not match the value count.

    Since longitude and latitude aren't integers (they have a decimal place) you should treat them as though they're strings; thus applying speech marks around the variables.

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