Jump to content

odd syntax error??


tomfmason

Recommended Posts

I have a class file that I just added another class to. It is a simple grouping of a few functions. I thought  I could right this class in 15 minutes without a problem. Well I was half right..lol

This is the error that I got.

Parse error: syntax error, unexpected ';', expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/www/mahedidu/includes/classes.inc.php on line 152


Line 152 is the last line of the file.. I thought oh great now I am going to have to inspect the file line by line. Well I did that and I don't see where the issue is. I will post the class in question.

[code]
<?php
class messages {

   function messageCount($username) {
          $status = 'new';
          $sql = mysql_query("SELECT * FROM `messages` WHERE `m_to` = '$username' AND `status` = '$status'");
          $count = mysql_num_rows($sql);
          if ($count == 1) {
 $amount = 'You have 1 new message.';
          } else {
 $amount = 'You have ' . $count . ' new messages.';
          }
          return $amount;
   }
   
   function inBox($username) {
        $messages = array();
         $sql = "SELECT `m_id`, `m_from`, DATE_FORMAT(m_date, '%M %D %Y') AS `formated_date`, TIME_FORMAT(m_time, '%r') AS `formated_date`, `subject` FROM `messages` WHERE `to` = '$username'";                           
         $res = mysql_query($sql);     
        if (mysql_num_rows($res) < 1) {
$mess = 'You have no messages';
return $mess;
        }else{
            while ($rw = mysql_fetch_assoc($res)) {
        $messages[] = '<tr><td bgcolor="#DEDED3" width="20%"><b>' . $rw['m_from'] . '</b></td>
        <td bgcolor="#DEDED3" width="20%"><b>' . $rw['m_subject'] . '</b></td>
        <td bgcolor="#DEDED3" width="15%"><b>' . $rw['formated_date'] . '</b></td>
        <td bgcolor="#DEDED3" width="15%"><b>' . $rw['formated_time'] . '</b></td>
        <td bgcolor="#DEDED3" width="10%"><a href="index.php?page=read&id=' . $rw['m_id'] .'"><b>Read</b></a></td>
        <td bgcolor="#DEDED3" width="10%">&nbsp;</td>
        <td bgcolor="#DEDED3" width="10%"><a href="index.php?page=delete&id=' . $rw['m_id'] .'"><b>Delete</b></a></td></tr>';
}
return $messages;
    }

    function sendMessage($from, $to, $subject, $message) {
          $status = 'new';
          $sql = "INSERT INTO `messages` (`m_from`, `m_to`, `m_date`, `m_time`, `m_subject`, `m_message`, `m_status`) VALUES ('$from', '$to', now(), now(), '$subject', '$message', '$status'";
          $res = mysql_query($sql);
    }

    function getMessage($id) {
          $message = array();
          $sql = "SELECT `m_id`, `m_from`, DATE_FORMAT(m_date, '%M %D %Y') AS `formated_date`, TIME_FORMAT(m_time, '%r') AS `formated_date`, `subject` FROM `messages` WHERE `m_id` = '$id'";
          $res = mysql_query($sql);
          while ($rw = mysql_fetch_assoc($res)) {
      $message['id'] = $rw['m_id'];
      $message['from'] = $rw['m_from'];
      $message['date'] = $rw['formated_date'];
      $message['time'] = $rw['formated_time'];
      $message['subject'] = $rw['m_subject'];
      $message['message'] = $rw['m_message'];
        }
        return $message;
    }

    function deleteMessage($id) {
          $sql = mysql_query("DELETE FROM `messages` WHERE `m_id` = '$id'");
          if (!$sql) {
$message = 'There was an error in deleteing your message. Please contact the webmaster';
          } else {
$message = 'Your message has been deleted';
          }
          return $message;
    }
}
?>[/code]

Can anyone see where I am going wrong..??

Thanks,
Tom
Link to comment
Share on other sites

Over here:
[code]<?php

  function inBox($username) {
  $messages = array();
      $sql = "SELECT `m_id`, `m_from`, DATE_FORMAT(m_date, '%M %D %Y') AS `formated_date`, TIME_FORMAT(m_time, '%r') AS `formated_date`, `subject` FROM `messages` WHERE `to` = '$username'";       $res = mysql_query($sql);
  if (mysql_num_rows($res) < 1) {
      $mess = 'You have no messages';
      return $mess;
  }else{
      while ($rw = mysql_fetch_assoc($res)) {
      $messages[] = '<tr><td bgcolor="#DEDED3" width="20%"><b>' . $rw['m_from'] . '</b></td>
<td bgcolor="#DEDED3" width="20%"><b>' . $rw['m_subject'] . '</b></td>
<td bgcolor="#DEDED3" width="15%"><b>' . $rw['formated_date'] . '</b></td>
<td bgcolor="#DEDED3" width="15%"><b>' . $rw['formated_time'] . '</b></td>
<td bgcolor="#DEDED3" width="10%"><a href="index.php?page=read&id=' . $rw['m_id'] .'"><b>Read</b></a></td>
<td bgcolor="#DEDED3" width="10%">&nbsp;</td>
<td bgcolor="#DEDED3" width="10%"><a href="index.php?page=delete&id=' . $rw['m_id'] .'"><b>Delete</b></a></td></tr>';
}
return $messages;
}

?>[/code]

You for got to close the else, you only closed the loop and the function, so the compiler thinks everything is inside the inbox function, and then it get's an error at the end because of a missing "}".

Orio.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.