Jump to content

add friend button on user profile not working


shorty3

Recommended Posts

Right ive got a user profile that i want a add friend button but i coded a little something what i fort wud work but no luck

<?php
session_start();
include "includes/db_connect.php";
include "includes/functions.php";
include"includes/smile.php";
logincheck();
$username=$_SESSION['username'];
$viewuser=$_GET['viewuser'];

$fetch=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$viewuser'"));
if (!$fetch){
echo "No such user";


$totalf = mysql_num_rows(mysql_query("SELECT * FROM friends WHERE username = '$viewuser' AND active='1'"));

$invite_text="<div>$username Has Sent You A Friend Request<br>
<input name=Yes_Accept type=submit id=yes value=Accept Invite class=abutton> <input name=No_accept type=submit value=Decline Invite class=abutton></div><input type=hidden name=invite_id value=$bar2>";
if (($_GET['fri'])){
$exicst=mysql_query("SELECT * FROM users WHERE username='$viewuser'");
$nums=mysql_num_rows($exicst);
$adding=mysql_fetch_object($exicst);
$already=mysql_num_rows(mysql_query("SELECT * FROM friends WHERE type='Friend' AND person='$viewuser' AND username='$username'"));
if ($already != "0"){
echo "<center><font color=orange><b><br>This user is already your friend.<br><br></font>";
}elseif ($already == "0"){


mysql_query("INSERT INTO `friends` ( `id` , `username` , `person` , `type` , `active`) 
VALUES (
'', '$username', '$viewuser', 'Friend' , '0'
)");
mysql_query("INSERT INTO `friends` ( `id` , `username` , `person` , `type` , `active`) 
VALUES (
'', '$viewuser', '$username', 'Friend' , '0'
)");
mysql_query("INSERT INTO `inbox` ( `id` , `to` , `from` , `message` , `subject` , `date` , `read`) 
VALUES (
'', '$viewuser', '$username', '$invite_text' , 'Friend Request' , '$date' , '0'
)");
$bar2=mysql_insert_id();
echo "<center><font color=orange><br>Your Friend Invitation Was Sent To $viewuser<br><br></font>";
exit();
}
}}
?>

<a href=?fri=Yes>Add Friend +</a>

 

It just adds a blank person and comes back with No Such User and Your Friend Invitation Was Sent To

 

I think ive put some things in the wrong place to be honest but as im not a pro i easily miss things

 

 

 

You are using the get-method.

 

$viewuser=$_GET['viewuser'];

 

Does the link on the 'add friend'-button include the variable 'viewuser'?

Like this:

 

<INPUT TYPE="BUTTON" VALUE="Add Friend" ONCLICK="window.location.href='thepage.php?viewuser=shorty3'">

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.