Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    70
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Adding Two If Considitions (Doing Same Task!!)

    Hey ,

    I want to add to if statements with two conditions if the username owns the post and if the user is an Administration Team Member how can i do this? (sorry for my bad englis tdoay im in an hurry I can/do speak english though)


    Heres the current code

    PHP Code:
    <?php
    session_start
    ();
    require 
    "../connect.php"

    $username $_SESSION['username']; 
    $get $_GET['sid'];
    $selection mysql_query ("SELECT * FROM users WHERE username='$username'") or die ("Query Error");
    $sel mysql_query ("SELECT * FROM status WHERE status_id='$get' AND posted='$username'") or die ("Error");

    while(
    $row mysql_fetch_array($selection))
    if (
    $row['permissions']== Admin){

    $updation mysql_query ("DELETE FROM status WHERE status_id='$get'") or die ("Query Error");
    $up2 mysql_query ("DELETE FROM comments WHERE sid='$get'") or die ("Error");
    if (
    $updation==true)
    echo 
    "Post Deleted Successfully!";
    }else{
    echo 
    "You Do Not Have Permission To Delete This Post";

    }
    echo 
    "<meta name='viewport' content='width=device-width' </";
    ?>


    What i want is


    PHP Code:
    <?php
    session_start
    ();
    require 
    "../connect.php"

    $username $_SESSION['username']; 
    $get $_GET['sid'];
    $selection mysql_query ("SELECT * FROM users WHERE username='$username'") or die ("Query Error");
    $sel mysql_query ("SELECT * FROM status WHERE status_id='$get' AND posted='$username'") or die ("Error");


    //mods can delete anything if needed
    while($row mysql_fetch_array($selection))
    if (
    $row['permissions']== Admin){

    //if its the post owner but not a mod, Mods can delete anything but if the user created the post
    then allow them to delete it aswill
    if ($row['poster']==$username_session)

    $updation mysql_query ("DELETE FROM status WHERE status_id='$get'") or die ("Query Error");
    $up2 mysql_query ("DELETE FROM comments WHERE sid='$get'") or die ("Error");
    if (
    $updation==true)
    echo 
    "Post Deleted Successfully!";
    }else{
    echo 
    "You Do Not Have Permission To Delete This Post";

    }
    echo 
    "<meta name='viewport' content='width=device-width' </";
    ?>
    What i want is if the user is also the post owner then they can also delete the post.

    I have tried num_rows & if $row['poster']==$username_session)
    but that want work with the required if statement if$row==mod)

    Hope yous understand what im lookng for (i need to 2 if statements togerher doing the same task so if the user posted the post or is a mod then they can delete the post.

    Thanks,

    Spudster
    Last edited by Spudster; 07-30-2012 at 12:44 AM. Reason: Adding comments

  • #2
    New Coder
    Join Date
    Jul 2012
    Posts
    70
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Still Need Help..

  • #3
    New to the CF scene
    Join Date
    Jul 2012
    Location
    Minneapolis, MN
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I believe what you are looking for is to use a binary operator in your if codition.

    In order to check two conditions at the same time where only one condition needs to be true, I'd use the 'or' binary operator. So instead of:

    Quote Originally Posted by Spudster View Post

    PHP Code:
    <?php
    ...
    //mods can delete anything if needed
    while($row mysql_fetch_array($selection))
    if (
    $row['permissions']== Admin){

    // if its the post owner but not a mod, Mods can delete anything but if the 
    // user created the post then allow them to delete it aswill
    if ($row['poster']==$username_session)
    ...
    ?>
    I would use something similar to this simple php example:

    PHP Code:
    <?php
    if((condition_1) or (condition_2)) {
      
    // statements to run if at least one of the two conditions is met
    }
    else {
      
    // statements to run if niether condition is met
    }
    ?>
    There is also an 'and' operator that will evaluate that both conditions are true. In that case, condition_2 is not evaluated if condition_1 is false. There is no point in evaluating condition_2 since the entire statement is already not met.
    Here is a simple 'and' operator example:

    PHP Code:
    <?php
    if((condition_1) and (condition_2)) {
      
    // statements to run if both conditions are met
    }
    else {
      
    // statements to run if one or none of the conditions are met
    }
    ?>
    So in your case, I would use the following block in your code:

    PHP Code:
    <?php
    if(($row['permissions']== Admin) or ($row['poster']==$username_session)) {
      
    // statements to run if the user has Admin priviledges or is the original poster
      
    $updation mysql_query ("DELETE FROM status WHERE status_id='$get'") or die ("Query Error");
      
    $up2 mysql_query ("DELETE FROM comments WHERE sid='$get'") or die ("Error");
      if (
    $updation==true) {
        echo 
    "Post Deleted Successfully!";
      } else {
        echo 
    "You Do Not Have Permission To Delete This Post";
      }
    }
    ?>

  • #4
    New Coder
    Join Date
    Jul 2012
    Posts
    70
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I was going to use an or statement but thought that would trigger a Syntax error.

    Will try that now it should work.

    Posting the new code shortly.

  • #5
    New Coder
    Join Date
    Jan 2010
    Location
    Canada
    Posts
    34
    Thanks
    11
    Thanked 4 Times in 4 Posts
    http://www.adminforums.org/threads/a...me-task.29538/

    Seriously, nobody is going to help you if you post the EXACT same question on multiple forums.

  • #6
    New Coder
    Join Date
    Jul 2012
    Posts
    70
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Um many people do the same thing its no big deal..

    Anyway this issue has been solved

    Thanks Everyone

  • #7
    New Coder
    Join Date
    Jul 2012
    Posts
    70
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Im trying to add 3 if conditions but it doesn't seem to work? like the above code but 3 conditions..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •