Invalid query: Unknown column in 'field list'
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: Invalid query: Unknown column in 'field list'

  1. #1
    Junior Member
    Join Date
    Nov 2006
    Posts
    27

    Question Invalid query: Unknown column in 'field list'

    I'm getting this error when I execute my form and it brings up the corresponding .php page.

    Invalid query: Unknown column 'DCS' in 'field list' Whole query: SELECT DCS#, CLIREF, GUAR, PAT, ADDR1, ADDR2, CITY, ST, ZIP, SS#, DOB, PHONE, DBAL, TBAL, PAID FROM crossroads10 WHERE CLIREF='ZQ02037/8558'

    Here is my code:

    PHP Code:

    <?

    $link
    =mysql_connect('host''database''password');
    if (!
    $link) {
        die(
    'Could not connect: ' .mysql_error());
    }

    else
    {
        
    // Connected to the database
        
    print("Successfully connected to the MySQL database server.<br>\n");
    }


    $cliacct=$_POST['clientnum'];

    $query "SELECT DCS#, CLIREF, GUAR, PAT, ADDR1, ADDR2, CITY, ST, ZIP, SS#, DOB, PHONE, DBAL, TBAL, PAID FROM crossroads10 WHERE CLIREF='$cliacct'";

    $result=mysql_query($query);

    if (!
    $result) {
       
    $message  'Invalid query: ' mysql_error() . "\n";
       
    $message .= 'Whole query: ' $query;
       die(
    $message);
    }


    while (
    $row mysql_fetch_assoc($result)) {
       echo 
    $row['GUAR'];
       echo 
    $row['PAT'];
       echo 
    $row['ADDR1'];
       echo 
    $row['ADDR2'];
       echo 
    $row['CITY'];
       echo 
    $row['ST'];
       echo 
    $row['ZIP'];
       echo 
    $row['SS#'];
       echo 
    $row['DOB'];
       echo 
    $row['PHONE'];
       echo 
    $row['DBAL'];
       echo 
    $row['TBAL'];
       echo 
    $row['PAID'];


    }



    ?>
    From what I've found, this should work. I've seen where others have had this problem but I have yet to find the solution. Any help would be appreciated.

    Thanks

  2. #2
    Senior Member
    Join Date
    Nov 2004
    Posts
    148
    without looking at your database dump file... my first guess would be the # sign in the column name. I would rename the column and see if that fixes it. Php and mysql are notorious for not liking special characters as column and variable names.
    Everytime I Idiot-proof something. The world comes up with a better idiot!!!!

  3. #3
    Junior Member
    Join Date
    Nov 2006
    Posts
    27
    I changed all the column headers to lowercase and removed the "#" signs. Now I get this error.

    Invalid query: No Database Selected Whole query: SELECT dcs, cliref, guar, pat, addr1, addr2, city, st, zip, social, dob, phone, dbal, tbal, paid FROM crossroads10 WHERE cliref='ZQ02037/8558'

  4. #4
    Senior Member
    Join Date
    Nov 2004
    Posts
    148
    that is your database connect script. You need to check it for a database name.
    Everytime I Idiot-proof something. The world comes up with a better idiot!!!!

  5. #5
    Junior Member
    Join Date
    Nov 2006
    Posts
    27
    Ok..I got it to find the database and it return the values with an echo statement. How do I assign column names to variables? Thanks

  6. #6
    Senior Member
    Join Date
    Nov 2004
    Posts
    148
    You might also look at this...

    $result=mysql_query($query);

    Try
    $result=mysql_query($query,$link);

    so it knows what connection for the query...
    Everytime I Idiot-proof something. The world comes up with a better idiot!!!!

  7. #7
    Senior Member
    Join Date
    Nov 2004
    Posts
    148
    $data=mysql_fetch_array($results);

    $var1=$data[0];
    $var2=$data[1];

    etctra

    you can also find out what your data offsets are by using this

    echo('<pre>');
    print_r($data);
    echo('</pre>');

    that will print out the first record of your array with all the offsets. the <pre> just makes it easier to read.
    Everytime I Idiot-proof something. The world comes up with a better idiot!!!!

  8. #8
    Junior Member
    Join Date
    Nov 2006
    Posts
    27
    cbrknight - I appreciate you taking the time to help me with this. Unfortunately I'm very new to all of this. I'm trying to put together a "web portal" for a client to access and look at their accounts. I'm not very familiar with the language yet.

    When I used this: echo $row['guarantor']; It worked just find.

    Now I want to use the print command so that I can format and put the information exactly where I want it on the page. Or can I use the echo command above within html formatting to get the same result?

    Thanks again...very much appreciated.

  9. #9
    Senior Member
    Join Date
    Nov 2004
    Posts
    148
    you can use echo $row['guarantor'];
    or set

    $guarantor = $row['guarantor'];

    and use echo $guarantor;

    I believe you can print also...

    but I never us print so couldnt tell you the pros and cons of echo vs. print
    Everytime I Idiot-proof something. The world comes up with a better idiot!!!!

  10. #10
    Senior Member
    Join Date
    Nov 2004
    Posts
    148
    as to html I would do it something like this

    <tr>
    <td>Guarantor Name: <?php echo $guarantor; ?> </td>
    </tr>

    or you can

    echo('
    <tr>
    <td>Guarantor Name: $guarantor </td>
    </tr>
    ')
    With the second method all the html is processed through php and you have to be careful with your quotes
    Everytime I Idiot-proof something. The world comes up with a better idiot!!!!

  11. #11
    Junior Member
    Join Date
    Nov 2006
    Posts
    27
    Thanks! Now that I see it, it's simple. Sometimes I make it harder than it should be. I'll give it a try and post my results.

  12. #12
    Senior Member
    Join Date
    Nov 2004
    Posts
    148
    I think I learn everthing in PHP the hard way... Good luck
    Everytime I Idiot-proof something. The world comes up with a better idiot!!!!

  13. #13
    Junior Member
    Join Date
    Nov 2006
    Posts
    27
    Ok...one more quick question...where do I put, for example, $guarantor = $row['guarantor']; in the code?

  14. #14
    Senior Member
    Join Date
    Nov 2004
    Posts
    148
    anywhere after the mysql_fetch_array.... and before you echo it out....
    Everytime I Idiot-proof something. The world comes up with a better idiot!!!!

  15. #15
    Junior Member
    Join Date
    Nov 2006
    Posts
    27
    That worked! You have no idea how much I appreciate your help. I've been fighting with this stuff for about 3 or 4 days. Slowly coming to understand though. Thanks Again.

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
  •