0

please correct this problem

id -- int
user_id -- int 
friend_id -- int
<?
session_start(); //starts session
mysql_connect("localhost", "root", "");
mysql_select_db("admin");



if ($user_id= $_SESSION['logged']){ //check if user is logged in

if($_GET['user_id']){ //gets userid 
$friend_id=$_GET['user_id']; //friend
$by = $user_id; //me
$query = "INSERT INTO friend_req ( 'friend_id , 'user_id' ) VALUES ( '$friend_id' , '$user_id' )"; //inserts the request
$result = mysql_query($query) or die(mysql_error());

echo ( "Friend request sent" ); //echo completion
} 
else {
echo ( "No request was made" ); // or no request sent
}
}
else {
echo ( "You need to be logged in" ); //not logged in
}
?>

<form action = 'friend_request.php?user_id=<?php echo $user_id= $_SESSION['logged']?>' method='post'>
    <input type = 'submit' value = 'Add as Friend'>
4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by diafol
0

code not display any option like that freind request send. and nothing happens when i press add freind button

please correct this problem

id -- int
user_id -- int 
friend_id -- int
<?
session_start(); //starts session
mysql_connect("localhost", "root", "");
mysql_select_db("admin");



if ($user_id= $_SESSION['logged']){ //check if user is logged in

if($_GET['user_id']){ //gets userid 
$friend_id=$_GET['user_id']; //friend
$by = $user_id; //me
$query = "INSERT INTO friend_req ( 'friend_id , 'user_id' ) VALUES ( '$friend_id' , '$user_id' )"; //inserts the request
$result = mysql_query($query) or die(mysql_error());

echo ( "Friend request sent" ); //echo completion
} 
else {
echo ( "No request was made" ); // or no request sent
}
}
else {
echo ( "You need to be logged in" ); //not logged in
}
?>

<form action = 'friend_request.php?user_id=<?php echo $user_id= $_SESSION['logged']?>' method='post'>
    <input type = 'submit' value = 'Add as Friend'>
0

Whether it showing "No request was made" option?
Check out the database connection using following code

<?php
$con = mysql_connect('localhost','root','');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
else
{
 echo "Connected";
}
?>

Print the value of the variables like user_id,$friend_id.

Edited by divyakrishnan: n/a

0

Check line 11 and 12. You use post method in form. But, you get with GET method.

if($_GET){ //gets userid
$friend_id=$_GET;

0

Maybe your table structure's not right. How about:

requester_id | acceptor_id | daterequest | status

Obviously, the first two fields are foreign fields of your user_id in your user table. The third is the date when request made (so you can resend the request at certain intervals, e.g. every three days if not accepted (1).

status, e.g. 0 = awaiting reply, 1 = accepted, 2 = rejected

BTW first two fields together are PK, so no duplicates.

My 2p.

Edited by diafol: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.