<?php
if(isset($_POST['name']) && isset($_POST['msg'])) {
$name = check(filter($_POST['name']));
$msg = check(filter($_POST['msg']));
if(mb_strlen($_POST['name']) < 3 or mb_strlen($_POST['name']) > 20) $err =  'Длина названия должна быть в пределах 3 - 20 символов';
if(mb_strlen($_POST['msg']) < 2 or mb_strlen($_POST['msg']) > 2500) $err =  'Длина сообщения должна быть в пределах 2 - 2500 символов';
if(!isset($err)) {
$time = time();
include 'unique_topic_id.php';
mysql_query("INSERT INTO `forum_topic` SET `id` = '$ready_id', `name` = '$name', `id_user` = '$user[id]', `time` = '$time', `id_razdel` = '$razdel[id]'");
$now_topic = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_topic` WHERE `time`  = '$time'"));
mysql_query("INSERT INTO `forum_comm` SET `msg` = '$msg', `id_user` = '$user[id]', `id_topic` = '$now_topic[id]', `id_razdel` = '$razdel[id]', `time` = '$time', `topic_content` = '1' ");
mysql_query("UPDATE `forum_topic` SET `last_msg_time` = '$time' WHERE `id` = '$now_topic[id]'");
if ($razdel['news_post'] == '1') {
mysql_query("UPDATE `user` SET `news_read` = '1'");
$_SESSION['dont_read_news_now'] = 'yes'; 
}
header("Location: /topic?id=$now_topic[id]");
$_SESSION['message'] = 'Топик создан!';
exit();
}else{
header("Location: /create_topic?id=$razdel[id]");
$_SESSION['err'] = $err;
exit();
}
}
?>