在数据库中获取其他用户的ID及其信息,

时间:2019-03-30 15:19:33

标签: php html mysql

我在使用mysql以另一个用户身份登录时如何获取所选用户的ID及其信息时遇到问题,这两个表相互内部联接,我只是不知道如何获取其他用户的ID,并将其传递到其他数据库上

if(isset($ _ POST ['send'])) {

$query =  "SELECT * FROM tblmessage INNER JOIN tblusers ON tblmessage.userid=tblusers.userid";
$res = mysqli_query($con,$query);

while ($row = mysqli_fetch_assoc($res)) 
{
    $receiverID = $row['userid'];
}

    $sender = $_SESSION['Email'];
    $receiver = $_POST['email'];
    $message = $_POST['textmessages'];
    $date = date("Y-m-d h:i:sa");

    $q = 'INSERT INTO `tblmessage`(`id`,`sender_name`,`receiver_name`,`receiver_id`,`message_text`,`date_time`,`userid`)
       VALUES("","'.$sender.'","'.$receiver.'","'.$receiverID.'","'.$message.'","'.$date.'","'.$user_id.'")';
    $r = mysqli_query($con, $q);

    if($r)
    {
            echo"<script>alert('Message Sent')</script>
                <script>window.location.href='messages.php?id=$receiverID';</script>";
    }   
    else
    {
        echo $q;
    }

}

0 个答案:

没有答案