Parse error: syntax error, unexpected '}'

Résolu
Bonjour, a tous j'ai un problème avec du php j'ai l'erreur suivante : Parse error: syntax error, unexpected '}' in /www/tydus/newscore.php on line 1

et voici le code du fichier :

<?php
}
define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';

if ($pun_user['g_id'] == PUN_GUEST)
error($lang_common['No permission']);
}
// Recover the game name and the score
$game_name = $HTTP_POST_VARS['game_name'];
// str_replace strips all spaces present in the score string
$score = str_replace(" ", "", $HTTP_POST_VARS['score']);
$topscore = 1;
$now = time();

// This is a fix for var "score" wich is send as "Score" and not as "score" like in game "Easter Egg Catch"
if(empty($score))
{
$score = $HTTP_POST_VARS['Score'];
}

if(!empty($game_name) && !empty($score))
{
// Find Topscore
$sql = 'SELECT rank_topscore, rank_score FROM '.$db->prefix.'arcade_ranking, '.$db->prefix.'users WHERE rank_player = '.$db->prefix.'users.id AND rank_game = "'.$game_name.'" ORDER BY rank_score DESC LIMIT 1';
$query = $db->query($sql) or error("Impossible to select topscore.", __FILE__, __LINE__, $db->error());
$line = $db->fetch_assoc($query);
if($line['rank_topscore'] = 1 && $line['rank_score'] < $score)
{
$sql = 'UPDATE '.$db->prefix.'arcade_ranking SET rank_topscore = '.$topscore.' WHERE rank_game = "'.$game_name.'"';
$query = $db->query($sql) or error("Impossible to update the topscore", __FILE__, __LINE__, $db->error());
$topscore = 1;
}
elseif($line['rank_topscore'] >= 0 && $line['rank_score'] <= $score)
{
$topscore = 1;
}
else
{
$topscore = 0;
}

$sql = 'SELECT * FROM '.$db->prefix.'arcade_ranking WHERE rank_player = '.$pun_user['id'].' AND rank_game = "'.$game_name.'"';
$query = $db->query($sql) or error("Impossible to select the user and game", __FILE__, __LINE__, $db->error());
if(mysql_num_rows($query) > 0)
{
$line = $db->fetch_assoc($query);
if($line['rank_score'] <= $score)
{
// Update new highscore
$sql = 'UPDATE '.$db->prefix.'arcade_ranking SET rank_score = '.$score.', rank_date = '.$now.' , rank_topscore = '.$topscore.' WHERE rank_player = '.$pun_user['id'].' AND rank_game = "'.$game_name.'"';
$query = $db->query($sql) or error("Impossible to update new highscore", __FILE__, __LINE__, $db->error());

$sql = 'SELECT game_id FROM '.$db->prefix.'arcade_games WHERE game_filename = "'.$game_name.'"';
$query = $db->query($sql) or error("Impossible to select the game", __FILE__, __LINE__, $db->error());
$gameid = $db->fetch_assoc($query);
echo '<script type="text/javascript">window.location= "arcade_ranking.php?id='.$gameid['game_id'].'"</script>';
}
else
{
// No new highscore
$sql = 'SELECT game_id FROM '.$db->prefix.'arcade_games WHERE game_filename = "'.$game_name.'"';
$query = $db->query($sql) or error("Impossible to select the game", __FILE__, __LINE__, $db->error());
$gameid = $db->fetch_assoc($query);
echo '<script type="text/javascript">window.location= "arcade_play.php?id='.$gameid['game_id'].'"</script>';
}
}
else
{
// Is there a score?
$sql = 'SELECT rank_score, rank_topscore FROM '.$db->prefix.'arcade_ranking WHERE rank_game = "'.$game_name.'" ORDER BY rank_score DESC, rank_topscore DESC';
$query = $db->query($sql) or error("Impossible to select the topscore", __FILE__, __LINE__, $db->error());
$line = $db->fetch_assoc($query);
if($line['rank_score'] <= 0 && $line['rank_topscore'] <= 0)
{
$topscore = 1;
}

// Add new Highscore
$sql = 'INSERT INTO '.$db->prefix.'arcade_ranking (rank_game, rank_player, rank_score, rank_topscore, rank_date) VALUES ("'.$game_name.'", '.$pun_user['id'].', '.$score.', '.$topscore.', '.$now.')';
$query = $db->query($sql) or error("Impossible to insert the new score", __FILE__, __LINE__, $db->error());

$sql = 'SELECT game_id FROM '.$db->prefix.'arcade_games WHERE game_filename = "'.$game_name.'"';
$query = $db->query($sql) or error("Impossible to select the game", __FILE__, __LINE__, $db->error());
$gameid = $db->fetch_assoc($query);
echo '<script type="text/javascript">window.location= "arcade_ranking.php?id='.$gameid['game_id'].'"</script>';
}
}

else

{
error($lang_common['No permission']);
}

?>

Merci d'avance
Configuration: Windows XP
Firefox 3.0.1

19 réponses

  1. Bon, alors si ton message d'erreur est exactement le même, je ne peux pas t'aider :-((
    Désolé
    1. Ouep ^^ et t'inkiete je m'y connait j'ai monter tout un forum xD et le code c'est pour le forum
      http://tydus.olympe-network.com/
      1. Y a un truc bizarre quand même :-)))

        Tu as enlevé les accolades et il te donne une erreur d'accolade à la 6 !!!!!

        As tu bien :
        - enregistré ta page après modif
        - renvoyer ta page en ftp
        - recharger ta page

        ?
        1. Ouep toujours en ligne 6 et j'ai mit comme tu m'a dit

          <?php

          define('PUN_ROOT', './');
          require PUN_ROOT.'include/common.php';

          if ($pun_user['g_id'] == PUN_GUEST)
          {error($lang_common['No permission']);
          }

          // Recover the game name and the score
          $game_name = $HTTP_POST_VARS['game_name'];
          // str_replace strips all spaces present in the score string
          $score = str_replace(" ", "", $HTTP_POST_VARS['score']);
          $topscore = 1;
          $now = time();
          1. Toujours "on line 6" dans ton message d'erreur??

            Sinon tu as bougé ton accolade ouverte là où je t'ai dit?
            1. J'ai recharger la page XD j'ai fait comme tu m'a dit mais toujours l'erreur donc sa me gonfle un peut ^^ je ne voit pas pourquoi il mes l'erreur
              1. Si tu as
                unexpected '}' in /www/tydus/newscore.php on line 6
                c'est qu'à priori tu n'as pas rechargé ta page.

                Mais en fait je ne suis pas sur qu'il faille l'accolade ouverte ici.

                Recharge d'abord ta page et sinon ouvre ton accolade avant error
                1. <?php
                  {
                  define('PUN_ROOT', './');
                  require PUN_ROOT.'include/common.php';

                  if ($pun_user['g_id'] == PUN_GUEST)
                  error($lang_common['No permission']);
                  }

                  // Recover the game name and the score
                  $game_name = $HTTP_POST_VARS['game_name'];
                  // str_replace strips all spaces present in the score string
                  $score = str_replace(" ", "", $HTTP_POST_VARS['score']);
                  $topscore = 1;
                  $now = time();

                  Voila ^^
                  1. J'ai mit comme tu m'a dit mais il y a toujours l'erreur Parse error: syntax error, unexpected '}' in /www/tydus/newscore.php on line 6
                    1. Le début de ton code est :

                      <?php
                      }
                      define('PUN_ROOT', './');
                      require PUN_ROOT.'include/common.php';

                      if ($pun_user['g_id'] == PUN_GUEST)
                      error($lang_common['No permission']);
                      }

                      Il faut que tu l'écrives comme ça :

                      <?php
                      {
                      define('PUN_ROOT', './');
                      require PUN_ROOT.'include/common.php';

                      if ($pun_user['g_id'] == PUN_GUEST)
                      error($lang_common['No permission']);
                      }
                      1. Le probleme c'est que je ne voit aucune accolade qui se ferme sans s'ouvrir et si je met { au debut sa refait la meme erreur que le premier code :( merci d'avence
                        1. Ouvre ton accolade au début au lieu de la supprimer sinon à la ligne 8 tu auras encore une accolade fermée toute seule.
                          1. Ton mesage d'erreur veut dire :

                            syntax error = erreur de syntaxe (écriture au niveau du script)

                            unexpected '}' = } innatendue on va dire. Il ne comprend pas ce que vient faire cette accolade.

                            on line 1 = à la ligne 1
                            1. Merci de vos conseilles j'ai refait le code mais l'erreur :
                              Parse error: syntax error, unexpected '}' in /www/tydus/newscore.php on line 8
                              Pourtant j'ai fait comme vous m'avez dit

                              Voici le code :

                              <?php

                              define('PUN_ROOT', './');
                              require PUN_ROOT.'include/common.php';

                              if ($pun_user['g_id'] == PUN_GUEST)
                              error($lang_common['No permission']);

                              // Recover the game name and the score
                              $game_name = $HTTP_POST_VARS['game_name'];
                              // str_replace strips all spaces present in the score string
                              $score = str_replace(" ", "", $HTTP_POST_VARS['score']);
                              $topscore = 1;
                              $now = time();

                              // This is a fix for var "score" wich is send as "Score" and not as "score" like in game "Easter Egg Catch"
                              if(empty($score))
                              {
                              $score = $HTTP_POST_VARS['Score'];
                              }

                              if(!empty($game_name) && !empty($score))
                              {
                              // Find Topscore
                              $sql = 'SELECT rank_topscore, rank_score FROM '.$db->prefix.'arcade_ranking, '.$db->prefix.'users WHERE rank_player = '.$db->prefix.'users.id AND rank_game = "'.$game_name.'" ORDER BY rank_score DESC LIMIT 1';
                              $query = $db->query($sql) or error("Impossible to select topscore.", __FILE__, __LINE__, $db->error());
                              $line = $db->fetch_assoc($query);
                              if($line['rank_topscore'] = 1 && $line['rank_score'] < $score)
                              {
                              $sql = 'UPDATE '.$db->prefix.'arcade_ranking SET rank_topscore = '.$topscore.' WHERE rank_game = "'.$game_name.'"';
                              $query = $db->query($sql) or error("Impossible to update the topscore", __FILE__, __LINE__, $db->error());
                              $topscore = 1;
                              }
                              elseif($line['rank_topscore'] >= 0 && $line['rank_score'] <= $score)
                              {
                              $topscore = 1;
                              }
                              else
                              {
                              $topscore = 0;
                              }

                              $sql = 'SELECT * FROM '.$db->prefix.'arcade_ranking WHERE rank_player = '.$pun_user['id'].' AND rank_game = "'.$game_name.'"';
                              $query = $db->query($sql) or error("Impossible to select the user and game", __FILE__, __LINE__, $db->error());
                              if(mysql_num_rows($query) > 0)
                              {
                              $line = $db->fetch_assoc($query);
                              if($line['rank_score'] <= $score)
                              {
                              // Update new highscore
                              $sql = 'UPDATE '.$db->prefix.'arcade_ranking SET rank_score = '.$score.', rank_date = '.$now.' , rank_topscore = '.$topscore.' WHERE rank_player = '.$pun_user['id'].' AND rank_game = "'.$game_name.'"';
                              $query = $db->query($sql) or error("Impossible to update new highscore", __FILE__, __LINE__, $db->error());

                              $sql = 'SELECT game_id FROM '.$db->prefix.'arcade_games WHERE game_filename = "'.$game_name.'"';
                              $query = $db->query($sql) or error("Impossible to select the game", __FILE__, __LINE__, $db->error());
                              $gameid = $db->fetch_assoc($query);
                              echo '<script type="text/javascript">window.location= "arcade_ranking.php?id='.$gameid['game_id'].'"</script>';
                              }
                              else
                              {
                              // No new highscore
                              $sql = 'SELECT game_id FROM '.$db->prefix.'arcade_games WHERE game_filename = "'.$game_name.'"';
                              $query = $db->query($sql) or error("Impossible to select the game", __FILE__, __LINE__, $db->error());
                              $gameid = $db->fetch_assoc($query);
                              echo '<script type="text/javascript">window.location= "arcade_play.php?id='.$gameid['game_id'].'"</script>';
                              }
                              }
                              else
                              {
                              // Is there a score?
                              $sql = 'SELECT rank_score, rank_topscore FROM '.$db->prefix.'arcade_ranking WHERE rank_game = "'.$game_name.'" ORDER BY rank_score DESC, rank_topscore DESC';
                              $query = $db->query($sql) or error("Impossible to select the topscore", __FILE__, __LINE__, $db->error());
                              $line = $db->fetch_assoc($query);
                              if($line['rank_score'] <= 0 && $line['rank_topscore'] <= 0)
                              {
                              $topscore = 1;
                              }

                              // Add new Highscore
                              $sql = 'INSERT INTO '.$db->prefix.'arcade_ranking (rank_game, rank_player, rank_score, rank_topscore, rank_date) VALUES ("'.$game_name.'", '.$pun_user['id'].', '.$score.', '.$topscore.', '.$now.')';
                              $query = $db->query($sql) or error("Impossible to insert the new score", __FILE__, __LINE__, $db->error());

                              $sql = 'SELECT game_id FROM '.$db->prefix.'arcade_games WHERE game_filename = "'.$game_name.'"';
                              $query = $db->query($sql) or error("Impossible to select the game", __FILE__, __LINE__, $db->error());
                              $gameid = $db->fetch_assoc($query);
                              echo '<script type="text/javascript">window.location= "arcade_ranking.php?id='.$gameid['game_id'].'"</script>';
                              }
                              }

                              else

                              {
                              error($lang_common['No permission']);
                              }

                              ?>
                              1. Tu fermes une accolade dès ta 1ère ligne
                                Essaies de la mettre dans l'autre sens peut etre.