Mostafa Elkady
Mostafa Elkady

Reputation: 5801

remember POST value when change the URL

how i can remember POST value when change the URL

Upvotes: 1

Views: 642

Answers (5)

thomasmalt
thomasmalt

Reputation: 1752

What you're trying to achieve seem a little convulted to, and I think it would be wise to rethink your solution when you have more ideas about how you could solve what you're trying to do.

The way I understand your process flow you have this: (pseudocode)

a.php posts form with field text(id=a1) to b.php
b.php processes the form and creates a link to b.php?id=<url>
when link is clicked b.php is run again, but without form this time only get.

So b.php does two things:

  1. process the form and generate a table with links
  2. process the links from the table

It seems to me you're mixing the two and forgets that they are separate requests.

There are several ways you can achieve what you want of course. here is a list of a couple:

  • You can do as is mentioned above: add the variables you want from your form to your url and retrieve them from _GET istead of _POST
  • Turn on sessions on your page and store the variables from _POST in the session and retrive them form there on the next request
  • create a new form with in b.php when creating the table and resubmit the form to be again.

Hope this helps.

Upvotes: 0

yangqi
yangqi

Reputation: 683

you can use a hidden input to pass the value of a1

<input type="hidden" name="a1" value="$_POST['a1']" />

this will pass a1 to next page

Upvotes: 1

bobince
bobince

Reputation: 536587

Pass the value of $_POST["a1"] in another parameter in the b.php?... URL so that it can be accessible in b.php's $_GET lookup later.

Maybe it's a cut-and-paste error, but this:

href="b.php?id=".$row["url"]."" target="_self"

doesn't make any sense, you seem to be trying to use double quotes inside a double-quoted string. Also, you're forgetting to HTML-encode your output, which results in XSS security holes, and you will also need to URL-encode content you're putting into a URL parameter.

<?php
    $url= 'b.php?id='.urlencode($row['url']).'&a1='.urlencode($_POST['a1']);
?>
<a href="<?php echo htmlspecialchars($url); ?>">
    <?php echo htmlspecialchars($row['title']); ?>
</a>

then

<li>
    <?php echo htmlspecialchars($row['name']); ?>
    (<?php echo htmlspecialchars($_GET['id']); ?>,
    <?php echo htmlspecialchars($_GET['a1']); ?>)
</li>

(You can define a helper function with a shorter name like h() to avoid having to type out echo htmlspecialchars() so much.)

Upvotes: 3

jatt
jatt

Reputation: 398

If you want pass data you can put it in link as query string and get it again with GET or put it in SESSION or COOKIE

Upvotes: 1

Your Common Sense
Your Common Sense

Reputation: 157917

Just add this value to to the query string of the link.
and change POST method to GET

Upvotes: -1

Related Questions