I
I
Ilkhomjon Matazimov2020-04-16 15:14:56
PHP
Ilkhomjon Matazimov, 2020-04-16 15:14:56

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>


In other pages I get the id of the article, via $_GET['id'], but it doesn't work in another page.

That is, it is not possible to redirect and add a comment to a specific article. - this code does not work in action
header("Location: /news.php?id={$_GET['id']}");

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilhomjon Matazimov, 2020-04-16
@mr_qpdb

Decided very easy.
I just added in the form:

<input type="hidden" name="article_id" value="<?=$_GET['id'];?>">

Then I passed this article_id to the page where the logic itself is: And that's it, now I have access to the id parameter from the url of the first page;)
$article_id = $_POST['article_id'];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question