From post.php
does not add the author to the database, in index.php
, respectively, does not receive the message
index.php
<?php include '../core/init.php'; $id = (int)$_GET['user_id']; if($id == 0) exit('Ид пользователя не передан'); $row = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `user_id`='".$id."'")); if(!isset($row['user_id'])) exit('Пользователя в базе нет'); echo '<img width = 120 height=150 src="../' . $row['profile'] . '"/>'; if (isset($_GET['user_id'])) {$id =$_GET['user_id']; } else { exit("Вы зашил на страницу без параметра!");} if (!preg_match("|^[\d]+$|", $id)) { exit("<p>Неверный формат запроса! Проверьте URL</p>"); } $result = mysql_query("SELECT * FROM `users` WHERE `user_id`='$id'"); $myrow = mysql_fetch_array($result); if (empty($myrow['username'])) { exit("Пользователя не существует! Возможно он был удален.");} ?> <html> <head> <title><?php echo $myrow['username']; ?></title> </head> <body> <h2>Пользователь "<?php echo $myrow['username']; ?>"</h2> <?php print <<<HERE <br>|<a href='../index.php'>Моя страница</a></br> HERE; if ($myrow['username'] == $login) { print <<<HERE <h2>Личные сообщения:</h2> HERE; $tmp = mysql_query("SELECT * FROM `messages` WHERE `poluchatel`='$login' ORDER BY `user_id` DESC"); $messages = mysql_fetch_array($tmp); if (!empty($messages['user_id'])) { do { $author = $messages['author']; printf(" <table> <tr> <td>Автор: <a href='user/index.php?user_id=%s'>%s</a><br> Дата: %s<br> Сообщение:<br> %s<br> </td> </tr> </table><br> ",$author,$messages['date'],$messages['text'],$messages['user_id']); } while($messages = mysql_fetch_array($tmp)); } else { echo "Сообщений нет"; } } else { print <<<HERE <form action='post.php' method='post'> <br> <h2>Отправить Ваше сообщение:</h2> <textarea cols='43' rows='4' name='text'></textarea><br> <input type='hidden' name='poluchatel' value='$myrow[username]'> <input type='hidden' name='user_id' value='$myrow[user_id]'> <input type='submit' name='submit' value='Отправить'> </form> HERE; } ?> </body> </html>
post.php
<?php include '../core/init.php'; protect_page(); $login = $_POST['username']; $result2 = mysql_query("SELECT `user_id` FROM `users` WHERE `username`='$login'"); $myrow2 = mysql_fetch_array($result2); if (isset($_POST['user_id'])) { $id = $_POST['user_id'];} if (isset($_POST['text'])) { $text = $_POST['text'];} if (isset($_POST['poluchatel'])) { $poluchatel = $_POST['poluchatel'];} $author = $_POST['author']; $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>"; ?>