There is a chat on php. On the right there is a block with all users. I need when clicking on any of them go to his profile. The question is how to implement this so that the profile itself is created every time? Here is the login code:
<?php session_start(); include 'db.php'; include 'all_users.php'; if (isset($_POST['email-e']) && isset($_POST['password-pass'])) { $email_e = mysqli_real_escape_string($mysqli,$_POST['email-e']); $password_pass = md5(md5($_POST['password-pass'])); $query = "SELECT id, email, password FROM users_data WHERE email = '$email_e' AND password = '$password_pass'"; $sql = mysqli_query($mysqli,$query) or die(mysqli_error()); if (mysqli_num_rows($sql) == 1) { $row = mysqli_fetch_assoc($sql); $_SESSION['user_id'] = $row['id']; $_SESSION['email-e'] = $row['email']; } else { echo 'User was not found!'; header("Location: login.html"); } } if (isset($_SESSION['email-e'])){ header("Location: chat.php"); } ?> Here is the chat code:
<?php session_start(); if(isset($_POST['exit'])) { //unset($_SESSION['user_id']); session_destroy(); header("Location: login.html"); exit; } include 'db_chat.php'; // header('Content-Type: text/html; charset=utf-8'); //echo trim($_SESSION['email-e'])." <br />"."Вы авторизованы <br />"; ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Chat</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <title>Chat</title> <link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet"> <style> input{font:12px arial} a{color:#00f;text-decoration:none} a:hover{text-decoration:underline} #wrapper,#loginform{margin:0 auto;padding-bottom:25px;background:#ebf4fb;width:504px;border:1px solid #acd8f0}#loginform{padding-top:18px}#loginform p{margin:5px} #chatbox{text-align:left;margin:0 auto;margin-bottom:25px;padding:10px;background:#fff;height:270px;width:430px;border:1px solid #acd8f0;overflow:auto} #usermsg{width:380px;height:50px;border:1px solid #acd8f0;border-radius:3px 3px 3px 3px}#submitmsg{width:70px;height:53px;border-radius:5px 5px 5px 5px;cursor:pointer}.error{color:#f00} #menu{padding:12.5px 25px 12.5px 25px} .welcome{float:left} .logout{float:right} .msgln{margin:0 0 2px 0}.profile{position:absolute;right:100px;top:10px;width:250px;height:450px;border:1px solid black;border-radius:5px 5px 5px 5px;box-shadow:2px 2px 2px 2px; overflow: scroll;} </style> </head> <body> <div id="wrapper"> <div id="menu"> <p class="welcome" style="font-family: 'Lobster', cursive; font-size:1.1em;">Welcome, <?php echo trim($_SESSION['email-e'])?><b></b></p> <form name="message" action="" method="post"> <p class="logout" name="logout"> <button name="exit" id="exit" href="login.php" style="cursor:pointer; border-radius:3px 3px 3px 3px; color:red;">Exit Chat</button> </p> </form> <div style="clear:both"></div> </div> <div id="chatbox"> <?php if(isset($_POST['submitmsg'])) { if(!empty($_POST['usermsg']) && is_string($_POST['usermsg'])) { $user_id = $_SESSION['user_id']; $username = $_SESSION['email-e']; $time = date("Ymd H:i:s"); $usermsg = trim($_POST['usermsg']); $sql_chat ="INSERT INTO users_chat (usermsg,user_id,time) VALUES('{$usermsg}','{$user_id}','{$time}')"; $res = mysqli_query($mysqli_chat,$sql_chat); } } $query_chat = "SELECT * FROM users_chat INNER JOIN users_data ON users_chat.user_id = users_data.id"; $res = mysqli_query($mysqli_chat,$query_chat); while($row_chat = mysqli_fetch_array($res)) { $user_id = $row_chat['user_id']; print '<div>'; echo 'Email:'.$row_chat['email'].'<br>'; print 'Time:'.' '.$row_chat['time'].'<br>'; print htmlspecialchars($row_chat['usermsg']).'<br><br>'; print '</div>'; } ?> </div> <form name="message" action="" method="post"> <input name="usermsg" type="text" id="usermsg" style="margin-left:25px;"> <input name="submitmsg" type="submit" id="submitmsg" value="Send" style="cursor:pointer; color:green;"/><br> <div class="profile"> <?php include 'db.php'; $query_chat = "SELECT email FROM users_data"; $res = mysqli_query($mysqli,$query_chat); while($row_chat = mysqli_fetch_array($res)) { echo 'Email:'.$row_chat['email'].'<br>'; } ?> </div> </form> </div> <form> </form> </body> </html> DB is working. Everything is connected and entered.
profile.php?uid=. On this page, you retrieveuidfrom the request and are looking for a user with that ID. - u_mulder