Jump to content

Recommended Posts

Here a proper way off doing it.

 

database table.

database info.

table name friends_table.

id int not null auto_increment primary key
friend_id int(40) not null
user_id int(40) not null
date int not null

 

please read everything.

<?php session_start();

//cureent user looking at the page got a session id $_SESSION['user_id']

//databse connection

//go to a profile page that a user wants to add a friend.


// this is a sql statement to get the current user profile info.

$sql="`SELECT` * `FROM` `users` WHERE `user_id`='$profile_id";
$res=mysql_querry($sql)or die(mysql_error());


// while loop to get the current profile_id .
while($row=mysql_fetch_assoc($res)){

// this is the link of a person on a profile.

echo "<a href='add_friend.php?cm1=add_friend&cmd={$row['profile_id']}'>Add me as a friend</a>";

// make sure the condition is set.

if(isset($_GET['cmd1'])&& $_GET['cmd1']=="add__friend"){


// put friends id in a variable.
$friends_id=$_GET['cmd1'];

// put current users id in a varable.
$user_id=$_SESSION['user_id'];

// use a timestamp to get the current date off adding a friend.

$date=time();

// insert into the database the info.

$sql="`INSERT` `INTO` `frinds_table`(`friend_id`,`user_id`,`date`)
`VALUES`('".mysqwl_real_escape_string($friends_id)."','".mysql_real_escape_string($user_id)."','".mysql_real_esape_string($date)."'";
$res=mysql_querry($sql)or die(mysql_error());
}
}
?>

showing user friends on profiles.

<?php session_start();

$sql="SELECT * FROM `friends_table`,`user_table` WHERE user_id='{$_SESSION['user_id']} AND
friends_table.friends_id=user_table.user_id";
$res=mysql_query($sq)or die(mysql_error());

while($show_users_friends=mysql_fetch_assoc($res)){

echo" This is my firend\n {$show_users_friends['username']}\n <br>
Picture\n <img src='http://pics/{$show_users_friends['there_picture']}'>";
}
?>

Here a proper way off doing it.

 

database table.

database info.

table name friends_table.

id int not null auto_increment primary key
friend_id int(40) not null
user_id int(40) not null
date int not null

 

please read everything.

<?php session_start();

//cureent user looking at the page got a session id $_SESSION['user_id']

//databse connection

//go to a profile page that a user wants to add a friend.


// this is a sql statement to get the current user profile info.

$sql="`SELECT` * `FROM` `users` WHERE `user_id`='$profile_id";
$res=mysql_querry($sql)or die(mysql_error());


// while loop to get the current profile_id .
while($row=mysql_fetch_assoc($res)){

// this is the link of a person on a profile.

echo "<a href='add_friend.php?cm1=add_friend&cmd={$row['profile_id']}'>Add me as a friend</a>";

// make sure the condition is set.

if(isset($_GET['cmd1'])&& $_GET['cmd1']=="add__friend"){


// put friends id in a variable.
$friends_id=$_GET['cmd1'];

// put current users id in a varable.
$user_id=$_SESSION['user_id'];

// use a timestamp to get the current date off adding a friend.

$date=time();

// insert into the database the info.

$sql="`INSERT` `INTO` `frinds_table`(`friend_id`,`user_id`,`date`)
`VALUES`('".mysqwl_real_escape_string($friends_id)."','".mysql_real_escape_string($user_id)."','".mysql_real_esape_string($date)."'";
$res=mysql_querry($sql)or die(mysql_error());
}
}
?>

 

This just causes a

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`SELECT` * `FROM` `users` WHERE `user_id`='1' at line 1

error

Please also remember this is a non tested code, and was done in a rush.

 

chaage this statement to this.

 

<?php
$sql="SELECT * FROM `users` WHERE `user_id`='$profile_id";
?>

 

 

and change this statement to this

 

<?php
   $sql="INSERT INTO `frinds_table`(`friend_id`,`user_id`,`date`)
   `VALUES`('".mysqwl_real_escape_string($friends_id)."','".mysql_real_escape_string($user_id)."','".mysql_real_esape_string($date)."'";
   $res=mysql_querry($sql)or die(mysql_error());
?>

 

you also might not need this sql statement as you might be getting the progile id off the user from the url.

 


// this is a sql statement to get the current user profile info.

$sql="`SELECT` * `FROM` `users` WHERE `user_id`='$profile_id";
$res=mysql_querry($sql)or die(mysql_error());


// while loop to get the current profile_id .
while($row=mysql_fetch_assoc($res)){

 

if the statement needs to be removed as your using a get to get the user's profile id from the url then please also remove the } <<< end off while loop brace.

 

 

Just tell me how your getting the profile id then ill finish the code.

 

 

Id rather try and solve my problem the way my database is already but yano :P

 

Its getting it from the person name, so the username is like ?user=name and then it looks in the database for a table with the member name as name :P And then basically it takes the id from that name and searchs for the table with that id with f after it..

 

E.g. name = bob then it looks for the id of bob = 1 and then it looks for and displays the data on table 1 f

 

Full Page:

<?
session_start();
include "config.php";
include "online.php";
include('emoticon.php');
$em = new Emoticon();
$em->add('','faces/bigsmile.png');
$em->add(':-D','faces/bigsmile.png');
$em->add(":'(",'faces/cry.gif');
$em->add("",'faces/smile.png');
$em->add(":-)",'faces/smile.png');
$em->add("",'faces/sad.png');
$em->add(":-(",'faces/sad.png');
$em->add(":@",'faces/angry.png');
$em->add(":-@",'faces/angry.png');
$em->add("+o(",'faces/ill.png');
$em->add("+O(",'faces/ill.png');
$em->add(":S",'faces/confused.png');
$em->add(":-S",'faces/confused.png');
$em->add(":-s",'faces/confused.png');
$em->add(":s",'faces/confused.png');
$em->add("",'faces/tongue.png');
$em->add("",'faces/tongue.png');
$em->add("",'faces/wink.png');
$em->add(":^",'faces/embarras.png');
$em->add(":|",'faces/bored.png');
$em->add(";o",'faces/shocked.png');
$em->add(";O",'faces/shocked.png');
$em->add("",'faces/shocked.png');
$em->add("",'faces/shocked.png');
$em->add("(h)",'faces/cool.gif');
$em->add("(H)",'faces/cool.gif');


?>
<head>
<link REL="STYLESHEET" TYPE="text/css" HREF="css.css">
</head>
<body>


<? 

$comm = str_replace( "", "<img src='faces/bigsmile.png'>", $comm );



  		 $user = $_GET["user"];
  		 $comment = $_GET["comment"];
  		 $add = $_GET["add"];
  		 $friend = $_GET["friend"];
		 $edit = $_GET["edit"];

		 $usernamem = $_SESSION['session_username'];

  $query = mysql_query("SELECT * FROM `members`");

  while($result = mysql_fetch_array($query)) {

  $id = $result["id"];
  $name = $result["name"];
  $email = $result["Email"];
  $age = $result["age"];
  $location = $result["location"];
  $aboutme = $result["aboutme"];
  $music = $result["music"];
  $films = $result["films"];
  $books = $result["books"];
  $buddy = $result["bestbuddy"];
  $photo = $result["photo"];
  $IDF = "$id f";
  $IDC = "$id C";


if($user == "$name") {

echo "<center>";
include "nav.php";
echo "
<div class='box'>
	<div class='image'>
		<img src='$image' width='200px' border='0'>
				<div class='friends' align='left'>
					";


            if($_SESSION['session_username'] == "$name") { echo "";
            } else {
            echo "<div style='float:right;'> - <a href='profile.php?user=$name&add=addfriend'>Add As Friend</a> - </div>";};
            echo "<h2>Friends</h2>";
      
if($add == "addfriend") {
     $friend = mysql_query("SELECT * FROM `members` WHERE `name` = '$usernamem'");
    
          while($friendd = mysql_fetch_array($friend)) {
             $fid = $friendd["id"];
          
                $IDFF = "$fid f";

           $addfriend = mysql_query("INSERT INTO `$IDFF` (`maten`, `matep`) VALUES ('$user', '$photo');");
          
           echo "Friend Added...";
	   	echo "<meta http-equiv=\"refresh\" content=\"2;url=profile.php?user=$name\">";
	   
	   };
	   
};


	   
$queryy = mysql_query("SELECT * FROM `$IDF`");

  while($resultt = mysql_fetch_array($queryy)) {
  
	 $maten = $resultt["maten"];
	 $matep = $resultt["matep"];

	 		 		 	  $iddd = $resultt["ID"];

	 echo "
					<div style='padding-left: 5px;'> - <a href='profile.php?user=$maten'>$maten</a>";

			if($_SESSION['session_username'] == "$name") { 
			 echo " <a href='profile.php?user=$name&friend=del$maten$iddd'>[X]</a>";};

									 echo "</div>";

						if($friend == "del$maten$iddd") {

									$del = mysql_query("DELETE FROM `$IDF` WHERE ID='$iddd' AND maten='$maten'");
									echo "<meta http-equiv=\"refresh\" content=\"2;url=profile.php?user=$name\">";
									echo "<div style='padding-left: 5px;'>$maten Deleted...</div>";
									};

						};

					echo "
				</div>
	</div>
		<div class='content' align='left'>";
		 if($_SESSION['session_username'] == "$name") { 
		 echo "
			<a href='profile.php?user=$name&edit=$name$id' class='edit'>[Edit]</a>";
			};

			if($edit == "$name$id") {
					if($_SESSION['session_username'] == "$name") {
						include "profileedit.php";
							} else {

					echo "BAD PERSON! Your not logged in with this username!";
					echo "<meta http-equiv=\"refresh\" content=\"3;url=profile.php?user=$name\">";

					};
			} else {
			echo "
			<h2><a href='profile.php?user=$name'>$name</a></h2>
			<div class='info'>
			<b>Location</b>:<br> - $location<br>
			<b>Age</b>:<br> - $age<br>
			<b>About Me</b>:<br> - $aboutme<br>
			<b>Music</b>:<br> - $music<br>
			<b>Films</b>:<br> - $films<br>
			<b>Books</b>:<br> - $books<br>
			<b>Best Buddy</b>:<br> - $buddy<br>
		</div>
		";};
		echo "
		<div class='contentt' align='left'>
			<h2>Comment - <a href='profile.php?user=$name&comment=add'>Add Comment</a></h2>";


if($_POST['subsend']) {

$comnn = $_SESSION['session_username'];
$ccomm = $_POST["ccom"];

$sub = mysql_query("INSERT INTO `$IDC` (`comn`, `comm`) VALUES ('$comnn', '$ccomm');");
echo "Comment Posted...";
				echo "<meta http-equiv=\"refresh\" content=\"2;url=profile.php?user=$name\">";
} else if($comment == "add") {
echo  $em->apply("
<div style='padding: 10px;'><form method='POST' action='profile.php?user=$name&comment=sub'>
<textarea style='width: 100%;' id='ccom' name='ccom'>Add comment here...</textarea><br>
<div align='right' style='padding-bottom: 10px; border-bottom: #41A317 2px solid;'>
<input type='submit' name='subsend' value='Post'></div></form>");
} else {

			$queryyy = mysql_query("SELECT * FROM `$IDC` WHERE `ID` <> 1 ORDER BY `ID` DESC");

  while($resulttt = mysql_fetch_array($queryyy)) {
  
	 $comn = $resulttt["comn"];
	 $comm = $resulttt["comm"];
	 		 	  $idd = $resulttt["ID"];

				 if($_SESSION['session_username'] == "$name") { 
	 echo $em->apply("<div style='margin-top: 4px; background-color:#52D017'>
	 <a class='deletec' href='profile.php?user=$name&comment=del$idd'>[Delete]</a> 
					<div style='padding-left: 5px;'> - <a href='profile.php?user=$comn'>$comn</a>
					<div style='padding-left: 15px;'> $comm</a></div></div></div>");}
					else {

	 echo $em->apply("<div style='margin-top: 4px; background-color:#52D017'>
					<div style='padding-left: 5px;'> - <a href='profile.php?user=$comn'>$comn</a>
					<div style='padding-left: 15px;'> $comm</a></div></div></div>");};






						if($comment == "del$idd") {

										echo "Comment Deleted...";

									$del = mysql_query("DELETE FROM `$IDC` WHERE ID='$idd'");
									echo "<meta http-equiv=\"refresh\" content=\"2;url=profile.php?user=$name\">";
									};
				};
		};
					echo "
	</div>
	</div>
	</div>
</div>
";
include "footer.php";
echo "</center>";

};

};


  mysql_close($ms);
  ?>
  
</body>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.