Hello guys, I am doing a Friend system on my website, and I did the friend request, to accept, but the friends list isn't alright in some part of code because it isn't take the correct id, anyone can help me?
- <?php
- $users = $_SESSION['username'];
- $connect = mysql_connect("localhost","root","") or die(mysql_error());
- mysql_select_db("website");
- $user = $_GET['u'];
- $sql = mysql_query ("SELECT * FROM users");
- $result = mysql_fetch_assoc($sql);
- $id3 = $result['id'];
- $selusers = mysql_query("SELECT * FROM u_friends WHERE friend='$users' OR username='$users'");
- $row = mysql_num_rows($selusers);
- if($row!=0) {
- echo "<h1>Amigos</h1>";
- echo "<table align='center'>";
- while($rows = mysql_fetch_assoc($selusers)) {
- $id2 = $rows['id'];
- $read = $rows['accepted'];
- if($read==1)
- if(isset($_SESSION['username'])&&$_SESSION['username']!=($rows['username'])) {
- echo "<tr>";
- echo "<td>";
- echo "<a href='index.php?id=profile&u=".$id3."'>".$rows['username']."</a>";
- echo "</td>";
- echo "</tr>";
- } else if(isset($_SESSION['username'])&&$_SESSION['username']==($rows['username'])) {
- echo "<tr>";
- echo "<td>";
- echo "<a href='index.php?id=profile&u=".$id3."'>".$rows['friend']."</a>";
- echo "</td>";
- echo "</tr>";
- } else {
- echo "<table><tr><td>Não há utilizadores!</td></tr></table>";
- }
- echo "</table>";
- }
- }
- else {
- echo "<table><tr><td>Não há utilizadores!</td></tr></table>";
- }
- ?>
Anyone can help me please?When it says $id3, that's the problem
The error is when I put the echo "<a href='index.php?id=profile&u=".$id3."'>".$rows['friend']."</a>";
And the structures:
- TABLE
users
( id
, int(11) NOT NULL AUTO_INCREMENT,username
varchar(200) NOT NULL,password
varchar(30) NOT NULL,email
varchar(500) NOT NULL,repeatemail
varchar(500) NOT NULL,country
varchar(200) NOT NULL,gender
varchar(60) NOT NULL,birthday
varchar(60) NOT NULL,date
date NOT NULL,random
varchar(20) NOT NULLactivated
tinyint(1) NOT NULL DEFAULT- PRIMARY KEY(
id
) - )
- TABLE
u_friends
( id
int(11) NOT NULL AUTO_INCREMENT,username
varchar(200) NOT NULL,friend
varchar(200) NOT NULL,date
date NOT NULL,- PRIMARY KEY(
id
) - )