Help with PHP error

View previous topic View next topic Go down

Jack
Jack
Beta Tester
Beta Tester
Forum Posts : 8
Member Since : 2011-11-02

PostJack 25/5/2012, 2:25 pm

Hi,

I'm trying to create a forum from scratch and until now I haven't encountered any problems that I haven't been able to fix. However, whilst trying to add a feature that allows users to comment via facebook, as well as via the forums I have encountered the error "Parse error: syntax error, unexpected $end" and no matter what I try I can't seem to get rid of it.

I have read through the code again and again and all of the curly brackets and ends to php code (?>) are correct. If someone could re-read the code for me and point out why I am getting this error I would be very gratful Smile


The code:
Code:

  <table class="categories" cellspacing="0" id="posts">
 
    <tr>
      <th class="top" style="width:
     
      <?php
     
      if(!isset($_GET["fb"]))
      {
      echo('80%;');
      }
     
      if(isset($_GET["fb"]))
      {
      echo('100%;');
      }
     
      ?>
     
      !important; text-align: center;" id="right"> <?php echo($_GET["title"]); ?> </th>
     
      <?php
     
      if(!isset($_GET["fb"]))
     
      {
     
      echo(' <th class="top" id="left" style="text-align: center;"> ');
     
      }
     
      ?>
     
      <?php
     
      if(!isset($_GET["fb"]))
      {
     
      if($_SESSION["rank"] !== "Administrator" && $_SESSION["rank"] !== "Moderator" && $_SESSION["rank"] !== "Member")
      {
        echo("<a href='login.php' title='Login to Reply to this Thread' style='color: white; text-decoration: none;'> Login To Reply </a>");
      }
       
      else
      {
        echo("<a href='create.php?type=post&thread=".$_GET["t"]."' title='Create thread' style='color: white; text-decoration: none;'>Reply</a>");
      }
      }
           
      ?>
     
      </a>  </th>
    </tr>
   
<?php



mysql_select_db("myphpweb_community", $con);


$x=$_GET["f"];
$rows = 0;
$t=$_GET["t"];
$num="<br><b>Number</b>";
$end = "";

$result = mysql_query("SELECT * FROM posts WHERE tid=$t ORDER by number");

if($_SESSION["rank"] !== "Administrator" && $_SESSION["rank"] !== "Moderator")
{
$num="";
$row["number"] ="";
}

while($row = mysql_fetch_array($result))
  {
 
 
  $rows=$rows+1;
 
  if($_SESSION["rank"] !== "Administrator" && $_SESSION["rank"] !== "Moderator")
  {
  $row["number"] = "";
  }
 
 
  if($row["author"] == $_SESSION["user"])
  {
  $link = "<br><b><a href='editor.php?num=".$row["number"]."&msg=".$row["message"]."' title='edit'> Edit </b>";
  }
 
  if(! isset($_GET["fb"]))
 
  {
 
  echo ("<tr class='post'>
 
  <td class='message' id='".$row["author_rank"]."' style='width: 80% !important;'>".$row["message"]."</td>
  <td class='left' id='".$row["author_rank"]."' stlye='width: 30%;'> <B>Author:</b> " . $row["author"] ."  <br><B>Rank:</b> " . $row["author_rank"]
  . $num ." ". $row["number"] . $link . "
 
  </td></tr>");
 
  }
 
  if(isset($_GET["fb"]))
 
  {
 
  echo ("<tr class='post'>
 
  <td class='message' id='".$row["author_rank"]."' style='width: 100% !important;'>".$row["message"]."<br><br> By ". $row["author"] . " , " .$row["author_rank"]."</td>
  </tr>");
 
  }
 
  if($rows == 1)
  {
 
  echo('<tr><td style="width: 50%;">
 
  <table border="0" id="comments" style="width: 100%; margin: -6px;"><tr>
 
  <td style="width: 50%; border: 0 !important; text-align: center; padding: 2px;"> <a href="javascript: forum()"> Reply via Forums </a> </td>
  <td style="width: 50%; border: 0 !important; text-align: center; padding: 2px;"> <a href="javascript: facebook()"> Reply via Facebook </a> </td>
 
  </tr></table>
 
  ');
 
  if(!isset($_GET["fb"]))
  {
  echo("<td>&nbsp;</td>");

  }
 
 
if(! isset($_GET["fb"]))
{

 
  }
 
  echo("</div>");
 
  if(isset($_GET["fb"]))
  {
  echo('
 
  <tr class="fbc-comments" id="fbc-comments"><td style="width: 80%;"><div class="fb-comments" data-href="'.$_SERVER["REQUEST_URI"].'"
  data-num-posts="15"
  data-width="1040px"></div></td></tr>
 
  ');
  }
  }
 
?>

  <tr>
    <th class="bottom" id="left" style="width:30%;">
     
      <?php
     
      if($_SESSION["rank"] == "Administrator" || $_SESSION["rank"] == "Moderator")
      {
      echo("<a href='moderate.php?action=hide&tid=" . $_GET["t"] . "' style='color: white; text-decoration: none;'> Moderate </a>");
      }
     
      ?>
     
     
    </th>
   
    <?php
   
    if(!isset($_GET["fb"]))
          {
   
          echo(' <th class="bottom" id="right" style="text-align: center;"> ');
         
          }
         
    if(isset($_GET["fb"]))
          {
         
          }
         
          ?>
         
         
          <?php
         
          if(!isset($_GET["fb"]))
          {
         
          echo($rows);
         
          }
         
          ?>
         
  </th>
  </tr>


Edit: Solved, turned out I was missing a curly bracket after all Embarassed. Could an Admin please lock this.
LGforum
LGforum
Moderator
Forum Posts : 77
Member Since : 2011-11-12

PostLGforum 28/5/2012, 5:32 am

You need to fix the code to be escaping values before querying the database. SQL injection is one of the biggest most important dangers to be aware of when writing PHP.

Also, you should use single quotes for strings that you are concatenating, and only use double quote marks for strings that require parsing for the inclusion of variable interpolation.

also changing the mysql_fetch_array to mysql_fetch_assoc would be better since your not using index's at any point. Not a biggy, but your making the SQL server do more than needed.

There's a few other things, but I can see your learning, so its good so far Smile Thumbs up!
Vanilla990
Vanilla990
Administrator
Forum Posts : 114
Member Since : 2011-10-30

PostVanilla990 28/5/2012, 5:36 am

Locked upon request.
Sponsored content

PostSponsored content

View previous topic View next topic Back to top

Similar topics

Create an account or log in to leave a reply

You need to be a member in order to leave a reply.

Create an account

Join our community by creating a new account. It's easy!


Create a new account

Log in

Already have an account? No problem, log in here.


Log in

 
Permissions in this forum:
You cannot reply to topics in this forum