views:

49

answers:

2

Hello, first off, I am a newbie with php (as well as coding in general). I have a website that has user profiles. On these profiles there are areas to comment in. I am trying to toggle 3 types of comment areas depending on

A. If you are signed in and looking at your own profile B. If you are signed in looking at someone elses profile C. If not signed in and looking at any profile

I have 3 text areas and with their own input types ( the third without an input as you don't get to comment if you are not signed in) all set up. I have tried a myriad of if and if else statements. I have been able to get all three work at some points, but for example, C. will have the type it should, and an extra one. The closest I have gotten, which is the code I am about to show is A. and B. are working properly, C. has B.'s charactoristics. I know that things are not escaped etc...but just trying to get the basic functionality working first,and then I will secure and polish.

Here is my code,thanks!

<form name="CommentBox" method="post" action="Profile.php?id=<?php echo $prof->id; ?>">
                         <?php if($auth->id == $prof->id) { echo  "<textarea name='A.'></textarea>
                                                                   <input type='submit' name='A.' value='Submit' class='post' />";}if($auth->id != $prof->id){
                                echo "<textarea name='B.'></textarea>
                                      <input type='submit' name='B.' value='Submit' class='post' />";}elseif(!$_SESSION['SITE']['AUTH']) { echo "<textarea name='C.' disabled>Please sign in to comment...</textarea>";
                            }?> 

                    </form>
+3  A: 

Your second if statement (if($auth->id != $prof->id)) should be an elseif

Rory
tried that already,and just tried again to make sure. Not doing the trick, same thing, echoing B. type where it should be C. type
Ralph The Mouf
if..else statements use the first branch where the condition is true, your condition (`$auth->id != $prof->id`) is probably testing true even when `$auth->id` is not set (because null != any other value). Try putting the elseif block for type C before type B.
Rory
THANKS Rory! That worked. preesh!
Ralph The Mouf
A: 

This should do it

if( !$_SESSION['SITE']['AUTH'] ) {
  echo 'Please sign in';
}

if( $auth->id == $prof->id ) {
  echo "A";
} else {
  echo "B";
}
Sudhanshu
That still echoes c and b
Ralph The Mouf
My answer and the comment I made on it apply here as well, turn the second `if` into an `elseif` and this solution will work. To clarify: the first condition will catch the case where the user isn't authenticated and the last two branches will be skipped. As it stands, the first condition does it's job, but because the `else` is part of a separate `if` statement, it gets executed as well. Hope my explanation is clear enough...
Rory