53 users online (0 members and 53 guests)  


  Results 1 to 5 of 5

Related

  1. Replies: 1
  2. mysql fetch array error please help    Forum: PHP Forum
    Replies: 10
  3. Error connecting to mysql    Forum: PHP Forum
    Replies: 1
  4. Error MySQL Error: 1064 - subqueries    Forum: PHP Forum
    Replies: 0
  1. #1
    dziad's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    2

    mySQL and PHP 1054 error

    Hi everyone

    While I've been trying to write an INSERT query, I encountered a strange error. Here's what the code looks like:

    Code:
    $Query = "INSERT INTO tableName(fieldA, fieldB, fieldC) VALUES($a, $b, $c);";
    $Query = mysql_real_escape_string($Query);
    $Q = mysql_query($Query);
    The code above causes 1054 error with message "Unknown column %s in field list", where %s is some sample data. The same code, but with apostrophes around variables causes 1064 error. The error message depends also on the data inserted. Numerical values can be inserted without any problems.

    Errors occurs only for fieldB and fieldC, which are TEXT columns. fieldA is CHAR and I haven't seen any problems during the data insertion into it.

    Do you have any clues?

    Regards from Poland.

  2. #2
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: mySQL + PHP. A strange 1054 error.

    my seggestion... try echo'ing the sql query... look it over... if you still cant figure it out... go into phpmyadmin and run the sql in there and see what it does.

    i bet there is something wrong with the values (i am no mysql expert but the ; might seem fishy too)

  3. #3
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: mySQL + PHP. A strange 1054 error.

    I think you're right, ALL - I'm pretty sure that ";" is only required at the command-line, and mysql_query appends it for you.

  4. #4
    dziad's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    2

    mySQL + PHP. A strange 1054 error.

    I think that the semicolon has nothing to it. The query itself was correct, but the way of assigment it to $Query wasn't so good. I've changed it to:
    Code:
    $Query = sprintf("INSERT INTO tableName(fieldA, fieldB, fieldC) VALUES('%s','%s','%s');", $a, $b, $b);
    and everything works fine.

    Thanks for your effort

  5. #5
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: mySQL + PHP. A strange 1054 error.

    Quote Originally Posted by dziad
    I think that the semicolon has nothing to it.
    mysql_query, from the horse's mouth ...

    Quote Originally Posted by php.net
    mysql_query
    (PHP 3, PHP 4, PHP 5)

    mysql_query -- Send a MySQL query
    Description
    resource mysql_query ( string query [, resource link_identifier] )


    mysql_query() sends a query (to the currently active database on the server that's associated with the specified link_identifier).

    Parameters


    query
    A SQL query

    The query string should not end with a semicolon.



Tags for this Thread