Как сделать ,чтобы комментарий добавлялся к тому id на которой ты пишешь
<div id="yakor" class="container4">
<?php
if (filter_has_var(INPUT_POST, 'send')) {
$name = filter_input(INPUT_POST, 'name');
$text = filter_input(INPUT_POST, 'text');
if (!$name or !$text) {
echo '<h1 id="error_comment">Вы не ввели все данные!!!</h1>';
} else {
$add_comment = mysqli_query($connection," INSERT INTO `comments` (`id`, `autor_comment`, `text`, `pupdate`, `arcticles_id`) VALUES (NULL, '".$name."', '".$text."', current_timestamp(),''");
}
}
?>
<form method="post">
<h1 id="zag_comment_add">Добавить свою комментарий</h1>
<input id="komentname" name="name" placeholder="Введите имя">
<input name="text" id="text_comment" placeholder="Напишите свой комментарий">
<button id="otp" name="send" href="#otp">Отправить</button>
</form>
</div>
Например на статье id 1 и я хочу чтобы когда пишешь комментарий на этой странице,то автоматически к комментарию присваивался к articles_id 1
Если нужны переменые по id ,то обращайтесь
Ответы (1 шт):
Автор решения: Pavel
→ Ссылка
Если я вас правильно понял, то
<div id="yakor" class="container4">
<?php
$commentName = '';
$commentText = '';
if (filter_has_var(INPUT_POST, 'send')) {
$name = filter_input(INPUT_POST, 'name');
$text = filter_input(INPUT_POST, 'text');
if(!$name or !text) {
if(!$name) $commentName = 'Вы не ввели имя';
if(!$text) $commentText = 'Введите текст сообщения';
}
else {
$add_comment = mysqli_query($connection," INSERT INTO `comments` (`id`, `autor_comment`, `text`, `pupdate`, `arcticles_id`) VALUES (NULL, '".$name."', '".$text."', current_timestamp(),''");
}
}
?>
<form method="post">
<h1 id="zag_comment_add">Добавить свою комментарий</h1>
<input id="komentname" name="name" placeholder="Введите имя"><span class='errorMessages'><?=$commentName;?></span><br>
<input name="text" id="text_comment" placeholder="Напишите свой комментарий"><span class='errorMessages'><?=$commentText;?></span>
<button id="otp" name="send" href="#otp">Отправить</button>
</form>
</div>