在php中添加好友系统

时间:2017-03-26 21:16:40

标签: php mysql

我正在尝试在php中构建一个朋友系统我有表,数据库和逻辑到位。我无法收到朋友请求接收者的身份证。 我有registeredusers friends updates表。 registeredusers表看起来像这样,

CREATE TABLE `registeredusers` (
`id` int(11) NOT NULL,
`FirstName` varchar(50) NOT NULL,
`LastName` varchar(50) NOT NULL,
`UserName` varchar(50) NOT NULL,
`Email` varchar(50) NOT NULL,
`Password` varchar(255) NOT NULL,
`ResetPassword` int(7) DEFAULT NULL,
`friends` int(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

friends

CREATE TABLE `friends` (
`friend_one` int(11) NOT NULL,
`friend_two` int(11) NOT NULL,
`status` enum('0','1','2') DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

请求者的ID将被插入到friend_two中,接收者的ID将进入friend_one。这是我的代码

<?php
include 'dbh.php';

$sql = "SELECT * FROM registeredusers";
$result = mysqli_query($connection,$sql);
$row = mysqli_fetch_assoc($result);

$username = $row['UserName'];

$requesterU = $_GET['user'];
echo "the requester is ".$requesterU;

while($row=mysqli_fetch_array($result)){

    $id = $row[0];
    $username = $row[1];



    echo "
    <form action='list of users.php'>
    $id $username<input type='submit' value='send request' name='friendsbanalo'></input></form>";

}



$sql = "SELECT * FROM  registeredusers WHERE UserName = '$requesterU'";
$result = mysqli_query($connection,$sql);
$row = mysqli_fetch_assoc($result);

$requester_id = $row['id'];
echo "requester's id ".$requester_id;




if(isset($_POST['friendsbanalo'])){

    $sql = "INSERT INTO friends (friend_one,friend_two) VALUES('$requester_id','$reciver_userid')";
    $result = mysqli_query($connection, $sql);
}else{
    echo "error";
}
?>

我无法获得接收者的身份证,任何人都可以告诉我如何获得接收者身份证?我试着寻找解决方案,答案太复杂了,我无法理解。我尝试(在一个单独的文件中)INNER JOIN但我无法让它工作。

0 个答案:

没有答案