Professional Web Applications Themes

Syntax frustration - MySQL

I'm getting a syntax complaint with the following query SELECT doents.DocPassportFirstName, doents.DocPassportFamilyName, countries.ConNationality, doents.DocPassportNo, doents.DocPassportIssueDate, doents.DocPassportPlaceOfIssue, doents.DocPassportExpiryDate, doents.DocDLFirstName, doents.DocDLFamalyName, doents.DocDLNationality, doents.DocDLNo, doents.DocBdcWith, doents.DocBdcPolNo, doents.DocBdcTelNo, doents.DocBdcExpiryDate, doents.DocMOTDue, doents.DocCCP, doents.DocCCPPolNo, doents.DocCCPTelNo, doents.DocUpDate FROM doents, countries WHERE doents.DocPassportNationalty = countries.ConID AND MemberID = $memberid; MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 I can't see what is wrong with it! Can anyone else see my mistake?...

  1. #1

    Default Syntax frustration

    I'm getting a syntax complaint with the following query

    SELECT doents.DocPassportFirstName,
    doents.DocPassportFamilyName,
    countries.ConNationality,
    doents.DocPassportNo,
    doents.DocPassportIssueDate,
    doents.DocPassportPlaceOfIssue,
    doents.DocPassportExpiryDate,
    doents.DocDLFirstName,
    doents.DocDLFamalyName,
    doents.DocDLNationality,
    doents.DocDLNo,
    doents.DocBdcWith,
    doents.DocBdcPolNo,
    doents.DocBdcTelNo,
    doents.DocBdcExpiryDate,
    doents.DocMOTDue,
    doents.DocCCP,
    doents.DocCCPPolNo,
    doents.DocCCPTelNo,
    doents.DocUpDate
    FROM doents, countries
    WHERE doents.DocPassportNationalty = countries.ConID
    AND MemberID = $memberid;

    MySQL Error: You have an error in your SQL syntax; check the manual
    that corresponds to your MySQL server version for the right syntax to
    use near '' at line 1

    I can't see what is wrong with it! Can anyone else see my mistake?

    Dan Guest

  2. #2

    Default Re: Syntax frustration

    On 31 Jan, 14:06, "Dan" <com> wrote: 

    try echoing the query

    strawberry Guest

  3. #3

    Default Re: Syntax frustration

    > try echoing the query

    I have and I can't spot the error :¬(


    Dan Guest

  4. #4

    Default Re: Syntax frustration

    On 31 Jan, 14:06, "Dan" <com> wrote: 

    I tried pasting it into phpMyAdmin and all it said to me was that the
    tables didn't exist. No SQL error was posted.

    Captain Guest

  5. #5

    Default Re: Syntax frustration

    On Jan 31, 3:30 pm, "Captain Paralytic" <com>
    wrote: 



    >
    > I tried pasting it into phpMyAdmin and all it said to me was that the
    > tables didn't exist. No SQL error was posted.[/ref]

    I suspect the error is in the contents of $memberid - but without
    seeing the echoed query it's difficult to tell.

    strawberry Guest

  6. #6

    Default Re: Syntax frustration

    Jerry Gitomer wrote:
     
    > Two suggestions. First, try putting $memberid in quotes. Second, verify
    > the spelling of each of your column names.[/ref]

    No - don't do that.
    Numbers should not be enclosed in quotes.
    Sanders Guest

  7. #7

    Default Re: Syntax frustration

    Dan wrote: 
    Two suggestions. First, try putting $memberid in quotes.
    Second, verify the spelling of each of your column names.

    HTH

    Jerry

    Jerry Guest

  8. #8

    Default Re: Syntax frustration

    strawberry wrote: [/ref]
     [/ref][/ref]
     [/ref][/ref]
     
    >
    > you don't know that it's a number[/ref]

    I don't know that the sun will rise tomorrow, either, but I'll
    bet you a PayPal dollar on it.

    For one thing - the error that came back wasn't ing about
    that particular problem. There's a different error that comes
    back for cast problems like that.

    This one is a *syntax* error. That means that somewhere there's
    a misspled word, an out-of-place comma, or an unclosed quote,
    comma or parenthesis.

    For another thing - ID's are like *always* numbers. Using the
    AUTO_NUMBER feature to create PK's named "id" is just too THE
    way to do it. If somebody does PK's in MySQL any other way -
    I'd always suggest they do it this way, instead.

    Indeed using that kind of PK instead of some string is probably
    the easiest way to speed up queries and such - because numbers
    are sooo NOT resource intensive to index.










    Sanders Guest

  9. #9

    Default Re: Syntax frustration

    On Jan 31, 11:50 pm, Sanders Kaufman <net> wrote: [/ref]
    > [/ref]
    > [/ref]

    >
    > No - don't do that.
    > Numbers should not be enclosed in quotes.[/ref]

    you don't know that it's a number

    strawberry Guest

  10. #10

    Default Re: Syntax frustration

    Dan wrote: 
    Is MemberID a field in doents or in countries table?
    I say near to near '' that's sign that $memberid is NULL
    and then you should use NULL in Field description and you didn't
    or some other thing

    show us more code
    and the table definition


    Cr♥sby Guest

  11. #11

    Default Re: Syntax frustration

    On 1 Feb, 00:48, Sanders Kaufman <net> wrote: 
    Think this out a little more Sanders!

    The query says
    AND MemberID = something

    The query pr is expecting "something" to be following the = sign.
    That is the correct "syntax" for a WHERE clause.
    If $memberid contains absolutely nothing, then the clause will end in

    AND MemberID =

    Which is incorrect syntax! The pr only sees the results after
    variables are resolved, it has no way to know that they was at one
    time a variable there which did not actually contain anything.

    Try doing a query

    SELECT * FROM table WHERE id =

    in phpmyadmin and you'll get a syntax error not a cast error.

    Captain Guest

  12. #12

    Default Re: Syntax frustration

    Captain Paralytic wrote:
     

    NULLs cause me sooooo much grief this way.
    Sanders Guest

  13. #13

    Default Re: Syntax frustration

    > The query says 


    I have had this problem before too... If the code puts up a blank
    entry for memberID, then it will give an error. Try outputting on the
    screen what the actual query will be once it's passed.

    The MySQL error usually tells you where the error in your syntax is
    (at what point it breaks), and in this case it's complaining about an
    empty entry at the end of the query...

    Nino

    nino9stars@yahoo.com Guest

  14. #14

    Default Re: Syntax frustration


    "Dan" <com> wrote in message
    news:googlegroups.com... 

    Do your really mean to spell 'famiIy' as 'famAly' ?


    Martin Guest

Similar Threads

  1. DB2 & Java Frustration -HELP!
    By sdfg in forum IBM DB2
    Replies: 2
    Last Post: September 9th, 04:13 PM
  2. Cache Frustration!
    By Renie83 in forum ASP
    Replies: 0
    Last Post: August 8th, 03:44 PM
  3. Frustration.
    By Frank Wheeler in forum Windows Setup, Administration & Security
    Replies: 1
    Last Post: July 19th, 09:12 PM
  4. XP Networking frustration
    By Brian Felty in forum Windows Networking
    Replies: 1
    Last Post: July 15th, 05:40 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139