Jump to content


Photo

odd syntax error??


  • Please log in to reply
2 replies to this topic

#1 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 26 October 2006 - 11:32 AM

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.

<?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;
    }	 
}
?>

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

Thanks,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 26 October 2006 - 11:37 AM

Over here:
<?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;
	}

?>

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.
Think you're smarty?

(Gone until 20 to November)

#3 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 26 October 2006 - 11:41 AM

LOL.. thanks.. I have been making alot of those small mistakes here lately..

Thanks again,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users