mysql query problem !!!

Discussion in 'PHP' started by nita, May 20, 2007.

  1. #1
    Hallo

    I need some help on spotting a bug or another solution in the following mysql query:
    i have table recipecat and columns - id, group, name...

    
     $result = mysql_query("SELECT * FROM recipecat WHERE group='Menuideas' ORDER BY name") or die(mysql_error());
    while($row = mysql_fetch_array( $result ))
            {
            echo "<A href='menuideas.php?cat=$row[name]'>$row[name]</a><br>";
            }
    
    PHP:
    getting following error from the browser:

    My php/mysql version is
    phpMyAdmin 2.7.0-pl1
    MySQL 4.0.24

    I have been using similar query before with no problems, there must be something wrong i do, well it is.
    i cant spot it.

    Thanks a lot for your advice

    Nita
     
    nita, May 20, 2007 IP
  2. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #2
    group is reserved word in mysql so you have to write:

    $result = mysql_query("SELECT * FROM recipecat WHERE `group`='Menuideas' ORDER BY name") or die(mysql_error());
    while($row = mysql_fetch_array( $result ))
            {
            echo "<A href='menuideas.php?cat=$row[name]'>$row[name]</a><br>";
            }
    PHP:
    with `group` instead of simple group
     
    gibex, May 20, 2007 IP
  3. coderbari

    coderbari Well-Known Member

    Messages:
    3,168
    Likes Received:
    193
    Best Answers:
    0
    Trophy Points:
    135
    #3
    yes if you use erserve words of mysql then it will show error.but many time we dont know what are those reserved words so it is better to put ' ' before and afer every name;it will make the work safe.
     
    coderbari, May 21, 2007 IP
  4. tamilsoft

    tamilsoft Banned

    Messages:
    1,155
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Not these ' ' use these ``
     
    tamilsoft, May 21, 2007 IP
  5. coderbari

    coderbari Well-Known Member

    Messages:
    3,168
    Likes Received:
    193
    Best Answers:
    0
    Trophy Points:
    135
    #5
    yes sorry about it.typing mistake :)
     
    coderbari, May 21, 2007 IP