How to remember POST value when change the URL?
I have got two page.
page a.php <form action="b.php" method="post"> <input id="a1" type="text" value="keyword" name="a1" /> <input type="submit" value="post"/> </form>page b.php <a href="b.php?id=".$row["url"]."" target="_self" >".$row["title"]."'.$_POST["a1"].'</a> <li>".$row["name"]."'.$_GET["id"].'</li>$row["url"],$row["title"] and $row["name"] are all query from mysql. After b.php received the $_POST value from a.php, it combined to a new hyperlink with $row["title"]. When click this hyperlink, the new value with $row["name"] in <UL> <LI>. Now when the url change to b.php?id=".$row["url"].", the $_POST value from a.php lost. How to deal with this problem? Thanks.
4 Answers
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:
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:
Hope this helps. Posted: greentree 1 of 1 people found this answer helpful. Did you? Yes No
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.) Posted: MacOS 2 of 2 people found this answer helpful. Did you? Yes No
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
Posted: greentree 2 of 2 people found this answer helpful. Did you? Yes No Thanks for anwser. How to put a value in SESSION or COOKIE?
Just add this value to to the query string of the link.
and change POST method to GET Posted: Go 1 of 1 people found this answer helpful. Did you? Yes No |
© Advanced Web Core. All rights reserved
Thanks friends, I have solved the problem. Have a nice day. :}
September 21, 2011