Answer the question
In order to leave comments, you need to log in
How to get id from url of another php page?
Good day.
I have a site with articles, where the id of the article is passed in the url.
There are also comments in these articles.
The functionality of adding a comment via php form action. It is not possible to pass the id of the article to this page action.
Here is the code:
<form action="ajax/comment_captcha_verify.php" method="post">
<?php if(!empty($_SESSION['login'])):?>
<label for="username">Ваше логин:</label>
<input type="text" readonly name="username" value="<?=$_SESSION['login']?>" id="username" class="form-control">
<label for="mess">Сообщение:</label>
<textarea name="mess" id="mess" class="form-control" placeholder="Введите комментарий"></textarea>
<!-- капча -->
<div class="g-recaptcha mt-3" data-sitekey="6LcsHucUAAAAAFq4qZqiDNYgcql3xAPFTpzvJxhh"></div>
<br>
<button id="mess_send" name="mess_send" class="btn btn-success mb-5">Добавить комментарий</button>
<div class="alert alert-danger" id="errorBlock"></div>
<?php else: ?>
<div class="alert alert-primary" role="alert">
Войдите в систему, чтобы оставлять комментарии
</div>
<?php endif;?>
</form>
header("Location: /news.php?id={$_GET['id']}");
Answer the question
In order to leave comments, you need to log in
Decided very easy.
I just added in the form:
<input type="hidden" name="article_id" value="<?=$_GET['id'];?>">
$article_id = $_POST['article_id'];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question