www.webdeveloper.com
Results 1 to 2 of 2

Thread: Highscore error!

  1. #1
    Join Date
    Nov 2005
    Location
    sweden
    Posts
    131

    Highscore error!

    yea well i made a highscore for the players on my server that gets uppdated every 12 hours but i seam to get a error around char
    here the code is
    PHP Code:
    <?php
    include('../../includes/config.php');
    mysql_query("TRUNCATE system_highscore");
    // lets start loading all the chars..
    $dir opendir($folderplayer);
    while(
    $file readdir($dir))
    {
        
    // checks that the file is a xml file
        
    $temp explode("."$file);
        if(
    $temp[1] == "xml")
        {
            
    $XML simplexml_load_string(file_get_contents($folderplayer $file));
            if(
    $XML['access'] > 2) continue;
            
            

            
    mysql_query("INSERT INTO system_highscore (char,skill,level) VALUES ('" $XML['name'] . "','level','".$XML['level']."')") or die(mysql_error());
            
    mysql_query("INSERT INTO system_highscore (char,skill,level) VALUES ('" $XML['name'] . "','maglevel','" $XML['maglevel'] . "') ") or die(mysql_error());
                    
            
    $i 0;
            
    $skills = array('fist','club','sword','axe','dist','shield','fishing');
            
    // Loop throw the skills and insert them
            
    foreach($XML->skills->skill as $skill)
            {
                
    mysql_query("INSERT INTO system_highscore 
                (char,skill,level,tries) 
                VALUES ('" 
    $XML['name'] . ",'" $skills[$i] . "','" $skill['level'] ."','" $skill['tries'] . "')
                "
    ) or die(mysql_error());
                
    $i++;
            }        
        }
    }
    ?>
    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 'char,skill,level) VALUES ('Azkuz','level','30')' at line 1

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,926
    "char" is a reserved word in MySQL, so you will need to back-tick your column of the same name. To be on the safe side, you can just back-tick all column and table names:
    Code:
    INSERT INTO `system_highscore` (`char`,`skill`,`level`,`tries`) ...[etc.]...
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

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
  •  
HTML5 Development Center



Recent Articles