Well, I'm trying to write a add friend script and he is working, but when my script (that is in a function) tries to search for $_GET['id']
to see what the id of the profile to make friend request, the script can't find because is a function that is in the profile.php and isn't directly in the file.
So I can made if I set the $_GET
a session, but if I enter in a user profile and then entre in another and if I try to make a friend request to the first profile, the request is sent to the last one ( that is registered in the session )
So how can I make a $_GET
"global"?
That's my code:
OTHER_PROFILE.PHP
<?php include_once("includes/head.php"); ?>
<?php require_once("includes/connect/connect.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php get_directory() ?>
<?php login_validation() ?>
<?php first_login(); ?>
<?php count_logins(); ?>
<?php get_shortcuts_menu_by_user(); ?>
<?php include_once("includes/body.php"); ?>
<?php
global $userid;
global $userid_profilee;
$_SESSION['userid'] = $userid;
$_SESSION['id'] = $_GET['id'];
?>
<script src="alert.js" ></script>
<?php
other_profile_main_photo();
echo "<br><br>";
?>
<?php include_once("includes/body_begin.php"); ?>
<?php echo "<br><br>";?>
<?php include("includes/footer.php"); ?>
FUNCTIONS.PHP (just the function part)
<?php require_once("/connect/connect.php"); ?>
<?php require_once("/jquery.php"); ?>
<?php
######### FRIEND REQUEST ########
function friend_request_send(){
global $db;
global $userid;
$userid = $_SESSION['userid'];
$userid_profilee = $_SESSION['id'];
$query_id_requester = "SELECT * FROM friend_requests";
$result_set1 = mysql_query($query_id_requester, $db) or die(mysql_error()) ;
$query_id_requests = "SELECT friend_requests FROM members WHERE id=\"{$userid_profilee}\" ";
$result_set3 = mysql_query($query_id_requests, $db) or die(mysql_error());
$query_id_requester_check = "SELECT * FROM friend_requests WHERE user_id=\"{$userid_profilee}\"";
$result_set4 = mysql_query($query_id_requester_check, $db);
$query_id_user_check = "SELECT * FROM friend_requests WHERE user_id_requester=\"{$userid}\"";
$result_set5 = mysql_query($query_id_user_check, $db);
## If already exists a friend request do this:
if ($id_requests = mysql_fetch_array($result_set3)){
if (($id_requester_check = mysql_fetch_array($result_set4)) && ($id_user_check = mysql_fetch_array($result_set5))){
echo "Ja fizeste pedido de Amizade!";
return ;
}
else
{
}
}
if ($id_requester = mysql_fetch_array($result_set1)){
$id_requests_1 = $id_requests['friend_requests'] + 1;
mysql_query("UPDATE members SET friend_requests=\"{$id_requests_1}\" WHERE id=\"{$userid_profilee}\"");
mysql_query("INSERT INTO friend_requests (user_id, user_id_requester) VALUES (\"{$userid_profilee}\", \"{$userid}\")");
echo "<div class=\"nNote nSuccess hideit\">
<p><strong>SUCCESS: </strong>Pedido de Amizade enviado com sucesso!</p>
</div>";
}
else
{
echo "Pedido de Amizade nao enviado!";
}
}
Thats the error if I try to change $userid_profilee = $_SESSION['id'];
to $userid_profilee = $_GET['id'];
Notice: Undefined index: id in C:\xampp\htdocs\includes\functions.php on line 13