Hi everyone!
I am doing in php that among users can be added as friends.
When I save the data I keep this name user1 logged and username2 of who wants to be friends.
User1 keep the session and when I click on follow me this appears
Unknown column 'UserSession in' field list 'the UserSession is the user name and not saved in the db.
Also when adding as a friend send a private message notification.
This is the index.php code
First shows all registered users and next button to add as friend

<?php
<table width="100%">
                  <tr>
                    <td width="13%" rowspan="2"><div style=" height:50px; overflow:hidden;"><a href="../../profile/profile.php?id=' . $userid . '" target="_self">' . $user_pic . '</a></div></td>
                    <td width="14%" class="style7"><div align="right">Nombre:</div></td>
                    <td width="73%"><a href="../../profile/profile.php?id=' . $userid . '" target="_self"><b>' . $username . '</b></a> </td>
                  	<td></td>
				  </tr>
                  <tr>
                    <td class="style7"><div align="right"></div></td>
                    <td><a href="follow.php"><img src="follow.png" border="0"/></a> </td>
                  </tr>
                  </table>
				  <hr />
?>

Follow.php code:

<?php

session_start();
include 'include/php/conexion.php';


$link=@dbConnect();
if (!$link) {
	echo "Error conecting to db."; 
}

if ($link =="202") {
	echo "Error selected the db.";
}


/* 0:delete,
   1:waiting,
   2:accepted */
   $username = $_POST['username'];
   $username = "";
	if ( isset($_SESSION['userid'])){
			$userid = $_SESSION['userid'];
			$username = $_SESSION['username'];
	$sql = 'INSERT INTO friends (username1,username2,status) VALUES ('.$_SESSION['username'].',$username,0)';
	$query = mysql_query($sql) or die(mysql_error());
	
	
		$title='Tip of friends';
		$to=$_POST['username'];
		$content=''.$username.' Want to be your friend.';
		$from= $_SESSION['username'];

		//do something here----store to db, send email
		mysql_query("INSERT INTO messages (from_user, to_user, message_title, message_content, message_date) VALUES ('$from','$to','$title','$content',now())") OR die("Could not send the message: <br>".mysql_error());
		echo '<b style="color:green;">It has sent the friend request!</b>';
	
	}else{
	header("Location:/login.php");
	}
?>

The problem is that when I click on a user I get this Unknown column 'usernameSession'in 'field list '.

Who can help me thank you.
Greetings! :)

Member Avatar for diafol

Use [ CODE ] instead of

Ok thanks!
This is code index.php.

<?php
<table width="100%">
<tr>
<td width="13%" rowspan="2"><div style=" height:50px; overflow:hidden;"><a href="../../profile/profile.php?id=' . $userid . '" target="_self">' . $user_pic . '</a></div></td>
<td width="14%" class="style7"><div align="right">Nombre:</div></td>
<td width="73%"><a href="../../profile/profile.php?id=' . $userid . '" target="_self"><b>' . $username . '</b></a> </td>
<td></td>
</tr>
<tr>
<td class="style7"><div align="right"></div></td>
<td><a href="follow.php"><img src="follow.png" border="0"/></a> </td>
</tr>
</table>
<hr />
?>

Follow.php code:

<?php

session_start();
include 'include/php/conexion.php';


$link=@dbConnect();
if (!$link) {
echo "Error conecting to db.";
}

if ($link =="202") {
echo "Error selected the db.";
}


/* 0:delete,
1:waiting,
2:accepted */
$username = $_POST['username'];
$username = "";
if ( isset($_SESSION['userid'])){
$userid = $_SESSION['userid'];
$username = $_SESSION['username'];
$sql = 'INSERT INTO friends (username1,username2,status) VALUES ('.$_SESSION['username'].',$username,0)';
$query = mysql_query($sql) or die(mysql_error());


$title='Tip of friends';
$to=$_POST['username'];
$content=''.$username.' Want to be your friend.';
$from= $_SESSION['username'];

//do something here----store to db, send email
mysql_query("INSERT INTO messages (from_user, to_user, message_title, message_content, message_date) VALUES ('$from','$to','$title','$content',now())") OR die("Could not send the message: <br>".mysql_error());
echo '<b style="color:green;">It has sent the friend request!</b>';

}else{
header("Location:/login.php");
}
?>
Member Avatar for diafol

erm, you've done it again!

This has been done a few times on this forum, search the forum for 'friends'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.