user6817600
user6817600

Reputation:

PhP -Passing Parameters in URL in Form

My URL contains parameters for database Query but when i submit my form on that same page these Parameters are gone .hence resulting in an error for database queries.

This is My URL

localhost/forum_original_code/article_details.php?article_id=3

This is the comment form i am trying to submit.

`<h4>Leave a Comment:</h4>
 <form class="well form-horizontal" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post"  id="contact_form">
 <div class="form-group">
  <textarea class="form-control" rows="3" name="comment"></textarea>
                       </div>
 <button type="submit" class="btn btn-primary">Submit</button>
 </form>

`

But when i get the posted values the Parameters form URL are gone.

URL After form submission

http://localhost/forum_original_code/article_details.php

Again resulting in data base query error. Can somebody guide me how to approach this better. Thanks.

Upvotes: 0

Views: 39

Answers (2)

Simrat Pal Singh
Simrat Pal Singh

Reputation: 158

Set action to

action="<?php echo htmlspecialchars($_SERVER["REQUEST_URI"]);?>"

It will return complete URL with query string.

$_SERVER["PHP_SELF"] only gives you till localhost/forum_original_code/article_details.php

Upvotes: 0

Tobias F.
Tobias F.

Reputation: 1048

You are using the POST method in your form. If you POST something you will not be able to see those values in the url. You can access these values via the superglobal $_POST['paramName']. For additional information consider to take a look at the PHP manual;

Upvotes: 1

Related Questions