This is coming soon!

Adding Two If Conditions (Doing Same Task)

Discussion in 'Programming Help & Discussion' started by Mr.Shy, Jul 30, 2012.

Oh noes!

You need 20 posts to be able to download resources, post links and other things. Read more...
  1. Mr.Shy Member

    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:
    <?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:
    <?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
  2. Mr.Shy Member

    I did forget to add the mysql_real_escaped i will work on security once i get it working.
  3. thomasr Member

    So you want to allow the user to delete the post if they posted it or if they have admin permissions? Try this:
    PHP:
    <?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' || $row['poster'] == $username) {
            
    $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' </";
    ?>
    I also cleaned up the code a bit by tabbing it.
    • Like Like x 2
    Loading...
  4. Mr.Shy Member

    Thanks :) is it possible to add two queries on in the while loop? the $row[poster] is on the status table and the $row['permissions'] is on the users table

    This should help me.
  5. thomasr Member

    Yeah that is possible but it would require a join or a union. It depends on relations between the tables, really and what you are trying to do. I know nothing about your table structures but here's a guess:
    Code:
    $selection = mysql_query ("SELECT u.*,s.* FROM users AS u LEFT JOIN status AS s ON u.username = s.poster WHERE u.username='$username' AND s.status_id='$get' AND s.posted='$username'") or die ("Query Error");
    So remove both those queries you have right now and replace the above with those queries. If that does not work then I may need to see your table structure or there may be an error with my query...
    • Like Like x 1
    Loading...
  6. Mr.Shy Member

    Thanks Alot! I will try it when i get home.
    And i did modifi the code it does work but the else statement stopped displaying.
  7. thomasr Member

    Okay I'll need to see the new code if you want me to figure out why the else statement isn't displaying.
  8. Mr.Shy Member

    PHP:
    <?php
    //*This might work!!
    if $row['username']==$username) or $row['admin']==Admin)
    echo 
    "You even own the post or are an Administrator";
    ?>
    I will try your code again and add the query

    Should be able to getg back to in 5-8 hours.

    Learnt you can use or statements so i could do this