jamesxg1 Posted February 6, 2009 Author Share Posted February 6, 2009 OK, lets see what you're actually getting; change friends.php to this; <?php $sql = "SELECT * FROM `friend` WHERE User_to = '{$_SESSION['username']}'"; $query = mysql_query($sql) or die (mysql_error()); while ($row = mysql_fetch_assoc($query)) { $User_to = $row['User_to']; $User_fr = $row['User_fr']; $Status = $row['Status']; } echo "SQL: $sql<br />"; echo "To: $User_to<br />"; echo "From: $User_fr<br />"; echo "Status: $Status<br />"; exit; ?> ok this is all i get now SQL: SELECT * FROM `friend` WHERE User_to = 'jamesxg1' To: From: Status: Link to comment https://forums.phpfreaks.com/topic/144071-solved-please-help-very-complicated-to-me/page/2/#findComment-756038 Share on other sites More sharing options...
jamesxg1 Posted February 6, 2009 Author Share Posted February 6, 2009 OK, lets see what you're actually getting; change friends.php to this; <?php $sql = "SELECT * FROM `friend` WHERE User_to = '{$_SESSION['username']}'"; $query = mysql_query($sql) or die (mysql_error()); while ($row = mysql_fetch_assoc($query)) { $User_to = $row['User_to']; $User_fr = $row['User_fr']; $Status = $row['Status']; } echo "SQL: $sql<br />"; echo "To: $User_to<br />"; echo "From: $User_fr<br />"; echo "Status: $Status<br />"; exit; ?> ok this is all i get now SQL: SELECT * FROM `friend` WHERE User_to = 'jamesxg1' To: From: Status: but once the code is changed to <?php $sql = "SELECT * FROM `friend` WHERE User_fr = '{$_SESSION['username']}'"; $query = mysql_query($sql) or die (mysql_error()); while ($row = mysql_fetch_assoc($query)) { $User_to = $row['User_to']; $User_fr = $row['User_fr']; $Status = $row['Status']; } echo "SQL: $sql<br />"; echo "To: $User_to<br />"; echo "From: $User_fr<br />"; echo "Status: $Status<br />"; exit; ?> that ^^ i get SQL: SELECT * FROM `friend` WHERE User_fr = 'jamesxg1' To: test From: jamesxg1 Status: Pending Link to comment https://forums.phpfreaks.com/topic/144071-solved-please-help-very-complicated-to-me/page/2/#findComment-756043 Share on other sites More sharing options...
gevans Posted February 6, 2009 Share Posted February 6, 2009 Simple, When you run this query SELECT * FROM `friend` WHERE User_to = 'jamesxg1' you get no results from your db Link to comment https://forums.phpfreaks.com/topic/144071-solved-please-help-very-complicated-to-me/page/2/#findComment-756047 Share on other sites More sharing options...
jamesxg1 Posted February 6, 2009 Author Share Posted February 6, 2009 Simple, When you run this query SELECT * FROM `friend` WHERE User_to = 'jamesxg1' you get no results from your db ok so now the code is this <?php $sql = "SELECT * FROM `friend` WHERE User_fr = '{$_SESSION['username']}'"; $query = mysql_query($sql) or die (mysql_error()); while ($row = mysql_fetch_assoc($query)) { $User_to = $row['User_to']; $User_fr = $row['User_fr']; $Status = $row['Status']; } ?> how do i make a IF statment that will match the username like so in the query and display the page if the status is set to OK and if it is set to Pending it will show a error message ? Link to comment https://forums.phpfreaks.com/topic/144071-solved-please-help-very-complicated-to-me/page/2/#findComment-756054 Share on other sites More sharing options...
gevans Posted February 6, 2009 Share Posted February 6, 2009 if($Status == 'Pending') { print("Sorry!, No can do you are still pending to be friends with $username"); } else { print("a different message"); } Link to comment https://forums.phpfreaks.com/topic/144071-solved-please-help-very-complicated-to-me/page/2/#findComment-756058 Share on other sites More sharing options...
jamesxg1 Posted February 6, 2009 Author Share Posted February 6, 2009 if($Status == 'Pending') { print("Sorry!, No can do you are still pending to be friends with $username"); } else { print("a different message"); } Works!, thanks mate one last thing is there anyway i can make that global ? Link to comment https://forums.phpfreaks.com/topic/144071-solved-please-help-very-complicated-to-me/page/2/#findComment-756061 Share on other sites More sharing options...
gevans Posted February 6, 2009 Share Posted February 6, 2009 When you say global do you mean have access to it across your whole site, or across functions etc.. Link to comment https://forums.phpfreaks.com/topic/144071-solved-please-help-very-complicated-to-me/page/2/#findComment-756063 Share on other sites More sharing options...
jamesxg1 Posted February 6, 2009 Author Share Posted February 6, 2009 When you say global do you mean have access to it across your whole site, or across functions etc.. sorry i didnt mean global :S, im a pain in the ass i know , i meant that the page will only be displayed if the Status is set to OK and if its not it will re-direct them ? Link to comment https://forums.phpfreaks.com/topic/144071-solved-please-help-very-complicated-to-me/page/2/#findComment-756068 Share on other sites More sharing options...
gevans Posted February 6, 2009 Share Posted February 6, 2009 use the code in your friends.php page like this; if($Status == 'Pending') { header('Location: redirect-page-here.php'); } Link to comment https://forums.phpfreaks.com/topic/144071-solved-please-help-very-complicated-to-me/page/2/#findComment-756070 Share on other sites More sharing options...
jamesxg1 Posted February 6, 2009 Author Share Posted February 6, 2009 use the code in your friends.php page like this; if($Status == 'Pending') { header('Location: redirect-page-here.php'); } doesnt do anything :S <?php $sql = "SELECT * FROM `friend` WHERE User_fr = '{$_SESSION['username']}'"; $query = mysql_query($sql) or die (mysql_error()); while ($row = mysql_fetch_assoc($query)) { $User_to = $row['User_to']; $User_fr = $row['User_fr']; $Status = $row['Status']; } if($Status == 'Pending') { header('Location: login.php'); } ?> Link to comment https://forums.phpfreaks.com/topic/144071-solved-please-help-very-complicated-to-me/page/2/#findComment-756072 Share on other sites More sharing options...
gevans Posted February 6, 2009 Share Posted February 6, 2009 sorry, if($Status == 'Pending') { header('Location: login.php'); exit; } Link to comment https://forums.phpfreaks.com/topic/144071-solved-please-help-very-complicated-to-me/page/2/#findComment-756079 Share on other sites More sharing options...
jamesxg1 Posted February 6, 2009 Author Share Posted February 6, 2009 sorry, if($Status == 'Pending') { header('Location: login.php'); exit; } Ok, worked!, how do i post the var $usernam from profile.php to ../db/friends.php and then i can get it on a diffrent paige ? Link to comment https://forums.phpfreaks.com/topic/144071-solved-please-help-very-complicated-to-me/page/2/#findComment-756101 Share on other sites More sharing options...
gevans Posted February 6, 2009 Share Posted February 6, 2009 set it in a session? Link to comment https://forums.phpfreaks.com/topic/144071-solved-please-help-very-complicated-to-me/page/2/#findComment-756112 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.