...

View Full Version : Adding Two If Considitions (Doing Same Task!!)



Spudster
07-30-2012, 12:30 AM
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
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
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

Spudster
07-30-2012, 03:05 AM
Still Need Help..

eeklund
07-30-2012, 03:20 AM
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:





<?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
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
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
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";
}
}
?>

Spudster
07-31-2012, 02:07 AM
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.

Cloud Ghost
08-11-2012, 09:47 AM
http://www.adminforums.org/threads/adding-two-if-conditions-doing-same-task.29538/

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

Spudster
08-12-2012, 12:09 AM
Um many people do the same thing its no big deal..

Anyway this issue has been solved

Thanks Everyone :)

Spudster
08-13-2012, 08:47 AM
Im trying to add 3 if conditions but it doesn't seem to work? like the above code but 3 conditions..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum