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
https://forums.phpfreaks.com/topic/25162-odd-syntax-error/
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
https://forums.phpfreaks.com/topic/25162-odd-syntax-error/#findComment-114694
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.