comment form logic

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

comment form logic

Post 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;			
		?>
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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'];
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post 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
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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;          
      ?>
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

problem still there....i still can see the comment box if viewing my own thread....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

there's an error in the sql syntax.. mysql_error() :?
Post Reply