mysql_fetch_array .. SQL syntax error?!

Discussion in 'PHP' started by Little Honey, May 12, 2012.

  1. #1
    Here's my code:

    $es_query = "SELECT `UserName` FROM `User` WHERE `UserType` = 1";
    $try_query = mysql_query($es_query or die(mysql_error()));
    $esnames = mysql_fetch_array($try_query or die(mysql_error()));
    PHP:
    I get the following 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 '1' at line 1

    This makes me cry. :confused:
     
    Little Honey, May 12, 2012 IP
  2. designdon

    designdon Greenhorn

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #2
    You have to complete bracket after $es_query and before or die statement thats the problem otherwise it will consider or die as a query too
     
    designdon, May 12, 2012 IP
  3. jonnyblaze

    jonnyblaze Greenhorn

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    $es_query = "SELECT `UserName` FROM `User` WHERE `UserType` = '1'";
    Try this

     
    jonnyblaze, May 13, 2012 IP
  4. webshore88

    webshore88 Well-Known Member

    Messages:
    131
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #4
    try this:

    $es_query = "SELECT `UserName` FROM `User` WHERE `UserType` = '1'";
    $try_query =
    mysql_query
    ($es_query) or
    die
    (
    mysql_error
    ());
    $esnames =
    mysql_fetch_array
    ($try_query) or
    die
    (
    mysql_error
    ());

    and make sure that your table name and its field are as same as you are coding in your script.
     
    webshore88, May 13, 2012 IP