Mancent Posted November 8, 2010 Share Posted November 8, 2010 <?php //include the connect script include "../../connect.php"; //Post variables from flash $username = $_POST['username']; $friend= $_POST['friend']; $status = $_POST['status']; $username = stripslashes($username); $status = stripslashes($status); $friend = stripslashes($friend); $username = mysql_real_escape_string($username); $status = mysql_real_escape_string($status); $friend = mysql_real_escape_string($friend); $sql = mysql_query("SELECT * FROM user_friends_list WHERE username = '$username'"); $rows = mysql_num_rows($sql); $your_username=$rows['username']; if($rows > 0) { $sql1 = mysql_query("SELECT * FROM user_friends_list WHERE username = '$username' and friend = '$friend' and status ='$status'"); $rows = mysql_num_rows($sql1); if($username && $friend && $status == "0" || $username && $friend && $status == "1") { echo "&msgTextfriendship= REQUESTED REJECTED ALREADY FRIENDS OR STATUS IS PENDING!"; return; } else { echo "&msgTextfriendship= REQUESTED NEW FRIEND SUCCESSFULLY!"; $insertnewfriend = mysql_query("INSERT INTO user_friends_list (username,friend,status) VALUES ('$friend','$username','0')") or die(mysql_error()); //$updateuserfriend = mysql_query("UPDATE user_friends_list SET status = '1' WHERE username = '$username' and friend = '$friend' and status ='0'"); return; } return; } else { echo "WiiStream Error!"; return; } ?> This right here I haven't tested it yet but I wanted to ask if this would work.. $sql1 = mysql_query("SELECT * FROM user_friends_list WHERE username = '$username' and friend = '$friend' and status ='$status'"); $rows = mysql_num_rows($sql1); if($username && $friend && $status == "0" || $username && $friend && $status == "1") { echo "&msgTextfriendship= REQUESTED REJECTED ALREADY FRIENDS OR STATUS IS PENDING!"; return; } Quote Link to comment https://forums.phpfreaks.com/topic/218063-help-with-a-if-statment-would-this-work/ Share on other sites More sharing options...
revraz Posted November 8, 2010 Share Posted November 8, 2010 Test it? Quote Link to comment https://forums.phpfreaks.com/topic/218063-help-with-a-if-statment-would-this-work/#findComment-1131598 Share on other sites More sharing options...
Mancent Posted November 8, 2010 Author Share Posted November 8, 2010 nope not working yet: my output says this ::TESTING THIS OUT FOR SEARCHING AND ADDING A FRIEND IF:: REQUESTED NEW FRIEND SUCCESSFULLY! And i tried to add myself as a friend and i'm already my friend so it should have said this ::TESTING THIS OUT FOR SEARCHING AND ADDING A FRIEND IF:: REQUESTED REJECTED ALREADY FRIENDS OR STATUS IS PENDING! Quote Link to comment https://forums.phpfreaks.com/topic/218063-help-with-a-if-statment-would-this-work/#findComment-1131603 Share on other sites More sharing options...
revraz Posted November 8, 2010 Share Posted November 8, 2010 Viola Quote Link to comment https://forums.phpfreaks.com/topic/218063-help-with-a-if-statment-would-this-work/#findComment-1131607 Share on other sites More sharing options...
Mancent Posted November 8, 2010 Author Share Posted November 8, 2010 ya I'm not getting it. I understand what it needs to do but I'm having a brain fart. ok it leaves from a flash file into the php file my username = $username post ok it leaves from a flash file into the php file my friend selection = $friend post now my php file has the two vars it needs ti insert into the mysql database. I need to do a check so i would select from friends list table where username = mancent if username = mancent and friends name = friends name send a response back to flash error already friends or pending.. But i don't know yet. <?php //include the connect script include "../../connect.php"; //Post variables from flash $username = $_POST['username']; $friend= $_POST['friend']; $status = $_POST['status']; $username = stripslashes($username); $status = stripslashes($status); $friend = stripslashes($friend); $username = mysql_real_escape_string($username); $status = mysql_real_escape_string($status); $friend = mysql_real_escape_string($friend); $sql = mysql_query("SELECT * FROM user_friends_list WHERE username = '$username'"); $rows = mysql_num_rows($sql); $your_username=$rows['username']; if($rows > 0) { $sql1 = mysql_query("SELECT * FROM user_friends_list WHERE username = '$username' and friend = '$friend' and status ='$status'"); $rows1 = mysql_num_rows($sql1); if($username && $friend && $status == "0" || $username && $friend && $status == "1") { echo "&msgTextfriendship= REQUESTED REJECTED ALREADY FRIENDS OR STATUS IS PENDING!"; return; } else { echo "&msgTextfriendship= REQUESTED NEW FRIEND SUCCESSFULLY!"; $insertnewfriend = mysql_query("INSERT INTO user_friends_list (username,friend,status) VALUES ('$friend','$username','0')") or die(mysql_error()); //$updateuserfriend = mysql_query("UPDATE user_friends_list SET status = '1' WHERE username = '$username' and friend = '$friend' and status ='0'"); return; } return; } else { echo "WiiStream Error!"; return; } ?> Would this have to post and get data so the var sent from flash is my username and my firend selection $friend= $_POST['friend']; $username = $_POST['username']; how can i use them vars and convert them over to get can i do this $getusername = $username; $getusername = $_GET['username']; would that still be mancent? Quote Link to comment https://forums.phpfreaks.com/topic/218063-help-with-a-if-statment-would-this-work/#findComment-1131651 Share on other sites More sharing options...
Mancent Posted November 8, 2010 Author Share Posted November 8, 2010 ok I'm just going to do it the only way i can think of. i hope you guys can help me with a better system. because this is going to be strange. I added a simple if statement code to say hey if I'm the user and I want to invite my self don't do it. it this line if($username == $friend) { //BLA BLA DONT DO IT return; } because when your register you have to be your self as a friend to see your commits you post. if not then you cant see your commits. I don't know why I did it that way, but thats just the way I had to do it. now I think I'm going to do a check system with a simple true statement $check = true; if($check==ture) { //Here is where I'm going to do a search using xml to get all my friends in a list and if i already invited a friend or the friend is pending then it will return the value back to flash. if its all clear move on and insert new friend. Its corning I know but I don't know any way else I can do it. return; } Well thats the idea. CORNY CORNIE <?php //include the connect script include "../../connect.php"; //Post variables from flash $username = $_POST['username']; $friend= $_POST['friend']; $username = stripslashes($username); $friend = stripslashes($friend); $username = mysql_real_escape_string($username); $friend = mysql_real_escape_string($friend); $sql = mysql_query("SELECT * FROM user_friends_list WHERE username = '$username'"); $rows = mysql_num_rows($sql); if($rows > 0) { //lets give it a checksystem $check=true; if($username == $friend || $friend == $username) { echo "&msgTextfriendship= IF IM ADDING MY SELF DO NOT DO IT!" ; return; } if($check==true) { // I COULD DO A XML SECTION HERE TO PRINT OUT ALL MY FRIENDS AND USE WHILE THEN CONTINUE WITH THE IF STATMENTS echo "&msgTextfriendship= IF I ALREADY INVITED THIS PERSON TO BE MY FRIEND DO NOT DO IT!" ; return; } else { echo "&msgTextfriendship= REQUESTED NEW FRIEND SUCCESSFULLY!"; $insertnewfriend = mysql_query("INSERT INTO user_friends_list (username,friend,status) VALUES ('$friend','$username','0')") or die(mysql_error()); //$updateuserfriend = mysql_query("UPDATE user_friends_list SET status = '1' WHERE username = '$username' and friend = '$friend' and status ='0'"); return; } return; } else { echo "WiiStream Error!"; return; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/218063-help-with-a-if-statment-would-this-work/#findComment-1131670 Share on other sites More sharing options...
Mancent Posted November 8, 2010 Author Share Posted November 8, 2010 well how about this? <?php //include the connect script include "../../connect.php"; //Post variables from flash $username = $_POST['username']; $friend= $_POST['friend']; $username = stripslashes($username); $friend = stripslashes($friend); $username = mysql_real_escape_string($username); $friend = mysql_real_escape_string($friend); $sql = mysql_query("SELECT * FROM user_friends_list WHERE username = '$username'"); $rows = mysql_num_rows($sql); if($rows > 0) { if($username == $friend || $friend == $username) { echo "&msgTextfriendship= SELFADD REJECTED!" ; return; } if(mysql_num_rows($sql) > 0) { while ($rows = mysql_fetch_assoc($sql)) { if($rows['username'] && $rows['friend'] && $rows['status'] == "0") { echo "&msgTextfriendship= PENDING STATUS!"; return; } if($rows['username'] && $rows['friend'] && $rows['status'] == "1") { echo "&msgTextfriendship= FRIENDS!"; return; } } } echo "&msgTextfriendship= REQUESTED NEW FRIEND SUCCESSFULLY!"; $insertnewfriend = mysql_query("INSERT INTO user_friends_list (username,friend,status) VALUES ('$friend','$username','0')") or die(mysql_error()); return; } else { echo "WiiStream Error!"; return; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/218063-help-with-a-if-statment-would-this-work/#findComment-1131674 Share on other sites More sharing options...
Mancent Posted November 8, 2010 Author Share Posted November 8, 2010 I got it. <?php //include the connect script include "../../connect.php"; //Post variables from flash $username = $_POST['username']; $friend= $_POST['friend']; $username = stripslashes($username); $friend = stripslashes($friend); $username = mysql_real_escape_string($username); $friend = mysql_real_escape_string($friend); $sql = mysql_query("SELECT * FROM user_friends_list WHERE username = '$username'"); $rows = mysql_num_rows($sql); if($rows > 0) { if($username == $friend || $friend == $username) { echo "&msgTextfriendship= SELFADD REJECTED!" ; return; } $newsql = mysql_query("SELECT * FROM user_friends_list WHERE username = '$username' and friend = '$friend'"); $newrows = mysql_num_rows($newsql); if(mysql_num_rows($newsql) > 0) { while ($newrows = mysql_fetch_assoc($newsql)) { if($newrows['username'] && $newrows['friend'] && $newrows['status'] == "0") { echo "&msgTextfriendship= PENDING STATUS!"; return; } if($newrows['username'] && $newrows['friend'] && $newrows['status'] == "1") { echo "&msgTextfriendship= FRIENDS!"; return; } if($newrows['username'] && $newrows['friend'] && $newrows['status'] == "2") { echo "&msgTextfriendship= WAITING!"; return; } } } echo "&msgTextfriendship= REQUESTED NEW FRIEND SUCCESSFULLY!"; $insertnewfriend = mysql_query("INSERT INTO user_friends_list (username,friend,status) VALUES ('$friend','$username','0')") or die(mysql_error()); $pendingnewfriend = mysql_query("INSERT INTO user_friends_list (username,friend,status) VALUES ('$username','$friend','2')") or die(mysql_error()); return; } else { echo "WiiStream Error!"; return; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/218063-help-with-a-if-statment-would-this-work/#findComment-1131684 Share on other sites More sharing options...
KevinM1 Posted November 8, 2010 Share Posted November 8, 2010 Can you fix your formatting? Some of your indents are out of control. Also, consolidate your code. For example, you can manipulate the form data in a mere two lines. $username = mysql_real_escape_string(stripslashes($_POST['username'])); Do the same for friend. You already obtain the number of db rows and assign it to $rows. You don't need to calculate it again. Finally, your second if-conditional has a redundancy in it. Remember, equality goes both ways. You don't need an 'or' there. Only write what you need to get something to work, don't repeat code, and trim the unneeded. It'll make it easier for anyone trying to help you to get to the heart of what you're trying to do. Good code is terse and readable. Quote Link to comment https://forums.phpfreaks.com/topic/218063-help-with-a-if-statment-would-this-work/#findComment-1131686 Share on other sites More sharing options...
Mancent Posted November 8, 2010 Author Share Posted November 8, 2010 thank you make scene. Hey would you check this out its what i was working on the friend system http://wiistream.net/WiiStream.swf Quote Link to comment https://forums.phpfreaks.com/topic/218063-help-with-a-if-statment-would-this-work/#findComment-1131700 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.