Page 1 of 1

comment form logic

Posted: Sun Mar 06, 2005 10:07 pm
by pleigh
i have a comment form in my page, here i limit the appearance of comment form to administrator status only.....now my problem is, if i am an administrator, i have the right to comment the message, i already done this, but i don't want the comment form to appear if i am viewing my own message/thread....here's my code below...

Code: Select all

<?
		$uid = $_SESSION&#1111;'userID'];
		$query = "SELECT status FROM users WHERE firstname='$fn' and status='administrator'";
		$result = @mysql_query($query);
		if (mysql_num_rows($result) != 0)
		&#123;
			$query = "SELECT userID FROM users WHERE userID='$uid'";
			$result = @mysql_query($query);
			if (!$result)
			&#123;
				include('commentform.php');
			&#125;
			else
			&#123;
				NULL;
			&#125;
		&#125;
		else
		&#123;
			NULL;
		&#125;			
		?>

Posted: Sun Mar 06, 2005 10:10 pm
by Burrito
just add something to your select to exclude the poster:

Code: Select all

"SELECT status FROM users WHERE firstname='$fn' and status='administrator' and posterid <> ".$_SESSION&#1111;'id'];

Posted: Sun Mar 06, 2005 10:15 pm
by pleigh
i did this

Code: Select all

$query = "SELECT status FROM users WHERE firstname='$fn' and status='administrator' AND postID <>".$_SESSION&#1111;'userID'];
it returned an error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\inetpub\wwwroot\mysample\reportviewbodycontent.php on line 98

Posted: Sun Mar 06, 2005 10:21 pm
by Burrito
instead of looking for a row count, just use mysql_fetch_assoc in your if. If there are no results, it will die.

example:

Code: Select all

<? 
      $uid = $_SESSION&#1111;'userID']; 
      $query = "SELECT status FROM users WHERE firstname='$fn' and status='administrator'"; 
      $result = @mysql_query($query); 
      if (mysql_fetch_assoc($result)) 
      &#123; 
         $query = "SELECT userID FROM users WHERE userID='$uid'"; 
         $result = @mysql_query($query); 
         if (!$result) 
         &#123; 
            include('commentform.php'); 
         &#125; 
         else 
         &#123; 
            NULL; 
         &#125; 
      &#125; 
      else 
      &#123; 
         NULL; 
      &#125;          
      ?>

Posted: Sun Mar 06, 2005 10:25 pm
by pleigh
problem still there....i still can see the comment box if viewing my own thread....

Posted: Mon Mar 07, 2005 12:29 am
by feyd
there's an error in the sql syntax.. mysql_error() :?