Jump to content

[SOLVED] please help very complicated (to me)


jamesxg1

Recommended Posts

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:

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

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 ?

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 ?

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 :D, 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 :)?

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');

} 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.