Hi,so i’ve been watching friend system from Well Bro on youtube and tried to add it into my website but here’s the problem:
[php]<?php
include ‘core/init.php’;
protect_page();
include ‘includes/overall/header.php’;
?>
if(user_exists($username) === true) {
$profile_user_id = user_id_from_username($username, 'username');
$my_id = $_SESSION['user_id'];
$profile_data = user_data($profile_user_id, 'username', 'first_name', 'last_name', 'email', 'profile');
?>
<h1><?php echo $profile_data['first_name']; ?>'s Profile</h1>
<?php
if($profile_user_id != $my_id) {
$check_friend_query = mysql_query("SELECT id FROM friends WHERE (user_one='$my_id' AND user_two='$profile_user_id') OR (user_one='$profile_user_id' AND user_two='$my_id')");
if(mysql_num_rows($check_friend_query) == 1) {
echo '<a href="">Already Friends - </a><a href="">Unfriend '. $profile_data['username'] .'</a>';
} else {
$from_query = mysql_query("SELECT id FROM friend_request WHERE from = '$profile_user_id' AND to = '$my_id'");
$to_query = mysql_query("SELECT id FROM friend_request WHERE from = '$my_id' AND to = '$profile_user_id'");
if (mysql_num_rows($from_query) == 1) {
echo '<a href="#">Ignore</a> or <a href="">Accept</a>';
} else if (mysql_num_rows($to_query) == 1){
echo '<a href="#">Cancel Request</a>';
} else {
echo '<a href="#">Send Friend Request</a>';
}
}
}
?>
<div class="profile_pic">
<?php if (empty($profile_data['profile']) === false) {
echo '<img class="profile_pic" src="' , $profile_data['profile'] , '" alt="', $profile_data['first_name'] , '\'s Profile Image">';
} ?>
</div>
<br><br><br><p>Email: <?php echo $profile_data['email']; ?></p>
<?php
} else {
echo '<h2>Sorry, that user does not exist!</h2>';
}
} else {
header(‘Location: index.php’);
exit();
}
include ‘includes/overall/footer.php’; ?>
I did in database everything correctly in friend_request i added from my user’s id and to user’s profile id,but it still shows me Send friend request.I was thinking maybe some kind of profile_user_id session is requiered but where and how do i add it? Here’s functions “user_id_from_username” and “user_data”
[php]function user_data($user_id) {
$data = array();
$user_id = (int)$user_id;
$func_num_args = func_num_args();
$func_get_args = func_get_args();
if($func_num_args > 1) {
unset($func_get_args[0]);
$fields = '`' . implode('`, `', $func_get_args) . '`';
$data = mysql_fetch_assoc(mysql_query("SELECT $fields FROM users WHERE user_id = $user_id"));
return $data;
}
}
function user_id_from_username($username) {
$username = sanitize($username);
return mysql_result(mysql_query(“SELECT user_id
FROM users
WHERE username
= ‘$username’”), 0, ‘user_id’);
}[/php]