After sending the message pops up: "Login to this page is allowed only to registered users!" If you remove the first half of the code? then everything works, only the author
entry is not added to the database, and the recipient does not see the letter, although it is entered into the database.
<?php session_start(); include '../core/init.php'; if (!empty($_SESSION['username']) and !empty($_SESSION['password'])) { $login = $_SESSION['username']; $password = $_SESSION['password']; $result2 = mysql_query("SELECT `user_id` FROM `users` WHERE `username`='$login' AND `password`='$password' AND `active`='1'"); $myrow2 = mysql_fetch_array($result2); if (empty($myrow2['user_id'])) { exit("Вход на эту страницу разрешен только зарегистрированным пользователям!"); } } else { exit("Вход на эту страницу разрешен только зарегистрированным пользователям!"); } if (isset($_POST['user_id'])) { $id = $_POST['user_id']; } if (isset($_POST['text'])) { $text = $_POST['text']; } if (isset($_POST['poluchatel'])) { $poluchatel = $_POST['poluchatel']; } $author = $_SESSION['username']; $date = date("Ymd"); $text = stripslashes($text); $text = htmlspecialchars($text); $result2 = mysql_query("INSERT INTO `messages` (`author`, `poluchatel`, `date`, `text`) VALUES ('$author','$poluchatel','$date','$text')"); //заносим в базу сообщение echo "<html><head><meta http-equiv='Refresh' content='1; URL=index.php?user_id=" . $id . "'></head></html>"; //перенаправляем пользователя ?>