title: syntax error, unexpected T_STRING, expecting ']'
body: <p>Could someone please explain why I am recieving this error in the below code and what I can do to fix it, error is referring to : <code>echo "&lt;tr&gt;&lt;td&gt;{$r['logID']}&lt;/td&gt;&lt;td&gt;&lt;a href='viewuser.php?u={$r['&gt;{$r['username']}&lt;/a&gt; [{$r['userID']}]&lt;/td&gt;&lt;td&gt;{$r['amount']}&lt;/td&gt;&lt;td&gt;&lt;a href='5050.php?chal={$r['&gt;Challenge&lt;/a&gt;&lt;/td&gt;&lt;td&gt;";</code></p>
  
  <p>To put it into context here is the whole snippet.</p>
  
  <pre><code>&lt;?php
  include "globals.php";
  $minbet=1;
  $maxg=10;
  echo "&lt;big&gt;50 / 50 Crystals Game&lt;/big&gt;";
  function add_game()
  {
          global $ir,$t,$userid, $db, $minbet, $maxg;
          if(!isset($_POST['amt']))
          {
              echo "&lt;big&gt;Adding a game&lt;/big&gt;
                  &lt;form action='5050.php?add=1' method='post'&gt;
                  Amount of crystals:&lt;input type='text' name='amt' size=10 maxlength=10&gt;
                  &lt;input type='submit' value='Add!'&gt;&lt;/form&gt;
                  ($maxg games max per user)
                  &lt;a href='5050.php'&gt;Back&lt;/a&gt;";
  
          }
      else
          {
              $_POST['amt'] = abs((int) $_POST['amt']); 
              if($_POST['amt'] &lt; $minbet)
                  {
                      echo "The minimum bet is $minbet
                          &lt;a href='5050.php?add=1'&gt;Back&lt;/a&gt;";exit;
                  }
              $theckcount=$db-&gt;query("SELECT logID FROM tchance WHERE userID={$ir['userid']} and active=1");
              if($db-&gt;num_rows($theckcount) &gt; ($maxg-1))
                  {
                  echo "There is a maximum of $maxg games per user.
                      &lt;a href='5050.php'&gt;Back&lt;/a&gt;";exit;
                  }
              if($ir['crystals'] &lt; $_POST['amt'])
                  {
                  echo "You cannot afford that amount.
                      &lt;a href='5050.php'&gt;Back&lt;/a&gt;";exit;
                  }
              $db-&gt;query("UPDATE users SET crystals = crystals - {$_POST['amt']} WHERE userid = {$ir['userid']}");
              $ir['crystals']=$ir['crystals'] - $_POST['amt'];
              $db-&gt;query("INSERT INTO tchance VALUES ('', {$ir['userid']}, {$_POST['amt']}, 1)");
              echo "Your game has been set.  Good Luck.
                  &lt;a href='5050.php'&gt;Back&lt;/a&gt;";
          }
  
  }
  function view_games()
  {
          global $ir,$t,$userid, $db, $maxg;
  
          $q=$db-&gt;query("SELECT t.*, u.username FROM tchance t left join users u on u.userid = t.userID WHERE t.active = 1 ORDER BY t.logID ASC");
  
          echo "&lt;a href='5050.php?add=1'&gt;Add Game&lt;/a&gt;
  
      Table of users awaiting a challenge
  
          &lt;table class='table' width=50%&gt;&lt;tr&gt;&lt;th&gt;Game ID&lt;/th&gt;&lt;th&gt;User&lt;/th&gt;&lt;th&gt;Amount&lt;/th&gt;&lt;th&gt;Challenge&lt;/th&gt;&lt;th&gt;Cancel&lt;/th&gt;&lt;/tr&gt;";
          if($db-&gt;num_rows($q) &lt; 1){echo "&lt;tr&gt;&lt;td colspan=5&gt;There are currenly no challenges&lt;/td&gt;&lt;/tr&gt;";}
          while($r=$db-&gt;fetch_row($q))
      {
          echo "&lt;tr&gt;&lt;td&gt;{$r['logID']}&lt;/td&gt;&lt;td&gt;&lt;a href='viewuser.php?u={$r['&gt;{$r['username']}&lt;/a&gt; [{$r['userID']}]&lt;/td&gt;&lt;td&gt;{$r['amount']}&lt;/td&gt;&lt;td&gt;&lt;a href='5050.php?chal={$r['&gt;Challenge&lt;/a&gt;&lt;/td&gt;&lt;td&gt;";
          if($ir['userid']==$r['userID']){echo "&lt;a href='5050.php?cancel={$r['&gt;Cancel&lt;/a&gt;";}             
          echo "&lt;/td&gt;&lt;/tr&gt;";
          }
          echo "&lt;/table&gt;";
          }
      function dogame()
          {
          global $ir,$t,$userid, $db;
          $_GET['chal'] = abs((int) $_GET['chal']);
          $q=$db-&gt;query("SELECT t.*, u.username from tchance t LEFT JOIN users u ON t.userID = u.userid Where t.logID={$_GET['chal']} AND t.active = 1 LIMIT 1");
          if($db-&gt;num_rows($q) &gt; 0)
          {
              $r=$db-&gt;fetch_row($q);
              if($ir['crystals'] &lt; $r['amount'])
                  {
                      echo "You cannot afford the challenge amount.
                      &lt;a href='5050.php'&gt;Back&lt;/a&gt;";exit;
                  }
                  if($ir['userid'] == $r['userID'])
                  {
                      echo "You cannot accept your own challenge.
                      &lt;a href='5050.php'&gt;Back&lt;/a&gt;";exit;
                  }
                  if(rand(1,2) == 1)
                  {
                      $winner=$r['userID']; $loser=$ir['userid'];
                      $winnername=$r['username'];
                      $losername=$ir['username'];
                      $tstring="Sorry, you Lost. Better luck next time.
                      &lt;a href='5050.php'&gt;Back&lt;/a&gt;";
                      $db-&gt;query("UPDATE users SET crystals = crystals - {$r['amount']} WHERE userid={$ir['userid']}");
                      $db-&gt;query("UPDATE users SET crystals = crystals + ({$r['amount']} * 2) WHERE userid={$r['userID']}");
                  }
                  else
                  {
                      $winner=$ir['userid']; $loser=$r['userID'];
                      $winnername=$ir['username'];
                      $losername=$r['username'];
                      $tstring="You Won! Congratulations! You Won {$r['amount']} crystals. 
                      &lt;a href='5050.php'&gt;Back&lt;/a&gt;";
                      $db-&gt;query("UPDATE users SET crystals = crystals + {$r['amount']} WHERE userid={$ir['userid']}");
                  }
                  event_add($winner, "The game of {$r['amount']} crystals challenged by &lt;a href='viewuser.php?u={$r['&gt;{$r['username']}&lt;/a&gt; was won by &lt;a href='viewuser.php?u={$winner}'&gt;{$winnername}&lt;/a&gt;.", $t);
                  event_add($loser, "The game of {$r['amount']} crystals challenged by &lt;a href='viewuser.php?u={$r['&gt;{$r['username']}&lt;/a&gt; was won by &lt;a href='viewuser.php?u={$winner}'&gt;{$winnername}&lt;/a&gt;.", $t);
                  $db-&gt;query("UPDATE tchance SET active = 0 WHERE logID={$_GET['chal']}");
                  echo $tstring;
          }
          else
          {
              echo "This game has either been cancelled or someone played before you got the 5050.
              &lt;a href='5050.php'&gt;Back&lt;/a&gt;"; exit;
          }
      }
  
  
  function cancel()
  {
      global $ir,$t,$userid, $db;
      $_GET['cancel'] = abs((int) $_GET['cancel']);
      $q=$db-&gt;query("SELECT * from tchance where logID={$_GET['cancel']} AND active = 1");
      if($db-&gt;num_rows($q) &gt; 0)
      {
          $r=$db-&gt;fetch_row($q);
          $db-&gt;query("UPDATE users SET crystals = crystals + {$r['amount']} WHERE userid = {$ir['userid']}");
          $ir['crystals']=$ir['crystals'] + $r['amount'];
          $db-&gt;query("UPDATE tchance SET active = -1 WHERE logID = {$_GET['cancel']}");
          echo "The game has been cancelled, and your crystals has been returned.
          &lt;a href='5050.php'&gt;Back&lt;/a&gt;";
      }
          else
      {
          echo "This game has already been canceled, does not exist, or someone already played.
          &lt;a href='5050.php'&gt;Back&lt;/a&gt;";
      }
   
  }
  
  if(isset($_GET['cancel'])){cancel();}
  elseif(isset($_GET['chal'])){dogame();}
  elseif(isset($_GET['add'])){add_game();}
  else{view_games();}
  
  ?&gt;
  </code></pre>
  
  <p>Thanks for taking the time to help me and teach me.</p>