SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    May 2004
    Location
    Jersey
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sql error is appearing in an identical copy of other code that works perfectly

    i have a strange problem: an sql error is appearing in an identical copy of code that works perfectly

    ive coded a section of a site. it works fine. the database holds the relevant data for a trek. that trek is in a country which is within a continent. the navigation menu uses these fields to select the trek and display the relevant information. it works fine. i used the same system for an equipment review system needed. same idea. the equipment is part of a section which is then part of a group. my database table comes out sumthing like this e.g.

    group: Kit Reviews
    section: Footwear
    kit_title: Super Duper Cool Shoe
    data: page data for that shoe

    the system works indentical to the trek selection system; which works flawlessly. i used the same code. editing the relevant text, variables and query information. and created the tables inside the database and added the information to them through my admin control panel.

    the page where you select which section u want to view (footwear, jackets, so on so on) uses identical code to the trek system. the equivalent trek page displays all countries within the selected continent inside a while loop. then under each country is listed the treks within it. i changed the table names, field names and variable names to match the equipment review table within the database. and have checked the table and everything quite a few times. nothing is wrong there.

    the sql error im getting is:
    Code:
    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 'group='Reviews' ORDER BY section ASC' at line 1
    the php error is:
    Code:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ........./kitreviews/selection.php on line 32
    here is the code on the selection.php page from within kitreviews
    PHP Code:
      switch ($group) {
            case "reviews": ?>
                          <font size="3" color="#0033CC"><b>Kit Reviews</b></font><br><br>
                         <?
                         $result 
    mysql_query("SELECT DISTINCT section FROM kits WHERE group='Reviews' ORDER BY section ASC") or die(mysql_error()); 
                          while(
    $row mysql_fetch_array($result)) { ?>
                         
                            <table border="0" width="80%" cellspacing="0" cellpadding="0">
                          <tr><td width="2">&nbsp;</td><td><font size="2" color="#0033CC"><b><? echo $row["section"]; ?></b></font></td></tr>
                         <?  $result2 mysql_query("SELECT * FROM kits WHERE section='"$row["section"] ."' ") or die(mysql_error());
                          while(
    $row2 mysql_fetch_array($result2)) { ?>
                         <tr><td width="2">&nbsp;</td><td>&nbsp;<img src="../../images/site_images/red_circle.png"><font size="1"><a href="kit.php?group=reviews&section=<? echo $row["section"]; ?>&kit_id=<? echo $row2["id"]; ?>"</a>
                         <? echo $row2["title"]; ?></a></font></td></tr><? ?></table><br><br><? } break; ....
    and here is the code from within the working trek selection page

    PHP Code:
    switch ($cont) {
            case "Africa": ?>
                          <font size="3" color="#0033CC"><b><? echo $_GET['cont'];?></b></font><br><br>
                         <?
                         $result 
    mysql_query("SELECT DISTINCT country FROM treks WHERE continent='Africa' ORDER BY country ASC");
                          while(
    $row mysql_fetch_array($result)) { ?>
                         
                            <table border="0" width="80%" cellspacing="0" cellpadding="0">
                          <tr><td width="2">&nbsp;</td><td><font size="2" color="#0033CC"><b><? echo $row["country"]; ?></b></font></td></tr>
                         <?  $result2 mysql_query("SELECT * FROM treks WHERE country='"$row["country"] ."' ");
                          while(
    $row2 mysql_fetch_array($result2)) { ?>
                         <tr><td width="2">&nbsp;</td><td>&nbsp;<img src="../../images/site_images/red_circle.png"><font size="1"><a href="treks.php?cont=Africa&country=<? echo $row["country"]; ?>&trek_id=<? echo $row2["id"]; ?>"</a>
                         <? echo $row2["trek"]; ?></a></font></td></tr><? ?></table><br><br><? } break; ......
    i can't seem to figure out why its coming up with the error. if i remove the WHERE clause from the kitreview/selection.php page it works fine. but it also displays information i don't want.

    any help greatly appreciated
    Matt Daly

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think the problem might be the word "group" is reserved word. so it is expecting something like "group by"
    try changin the column name. i had this error once and it fixed. but not sure it would work this time or not.

  3. #3
    SitePoint Addict launchcode's Avatar
    Join Date
    Dec 2004
    Location
    Bristol, UK
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not 100% sure, but I think you'll find that "group" is a reserved word in MySQL because you use it to, well.. group stuff Try renaming your column?
    Richard Davey

    Launchcode
    PHP Security Guide. Think your scripts are secure? Think again.

  4. #4
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    Finland
    Posts
    703
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    GROUP is a reserved word. Replace
    PHP Code:
    $result mysql_query("SELECT DISTINCT section FROM kits WHERE group='Reviews' ORDER BY section ASC") or ... 
    with
    PHP Code:
    $result mysql_query("SELECT DISTINCT section FROM kits WHERE `group` = 'Reviews' ORDER BY section ASC") or ... 
    Backticks make MySQL treat "group" as a regular string.

  5. #5
    SitePoint Zealot
    Join Date
    May 2004
    Location
    Jersey
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank u all. works now
    Matt Daly


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
  •