Сообщения пользователям
Таблица messages
id int (11) unsigned primary AI
body text
sender int (11) unsigned
receiver int (11) unsigned
read tinyint (1) unsigned
Создадим страницу
send-message.php
<h1>Send a
Message</h1>
<form
action="send-message.php?receiver=<?php echo
$_GET['receiver']; ?>" method="post">
<textarea
name="body" cols="80" rows="8"></textarea>
<input
type="submit" name="send" value="Send
Message"/>
</form>
Наберем
в строке получателя:
http://newsocial.loc/send-message.php?receiver=4
Продолжаем
send-message.php
<?php
include('./classes/DB.php');
include('./classes/Login.php');
if
(Login::isLoggedIn()) {
$userid =
Login::isLoggedIn();
} else {
die ('Not
logged in!');
}
if
(isset($_POST['send'])) {
if
(DB::query('SELECT id FROM users WHERE id =:receiver',
array(':receiver'=>$_GET['receiver']))) {
DB::query("INSERT INTO messages VALUES(:id, :body, :sender,
:receiver, 0)", array(':id'=>null, ':body'=>$_POST['body'],
':sender'=>$userid,
':receiver'=>htmlspecialchars($_GET['receiver'])));
echo
"Message Sent!";
} else {
die('Invalid ID!');
}
}
?>
<h1>Send a
Message</h1>
<form
action="send-message.php?receiver=<?php echo
htmlspecialchars($_GET['receiver']); ?>" method="post">
<textarea
name="body" cols="80" rows="8"></textarea>
<input
type="submit" name="send" value="Send
Message"/>
</form>
Комментариев нет:
Отправить комментарий