nikhar021 Posted April 18, 2008 Share Posted April 18, 2008 i need to pass a variable to two pages using post. how can this be accomplished????? help me out Link to comment https://forums.phpfreaks.com/topic/101682-passing-variables/ Share on other sites More sharing options...
Rowno Posted April 18, 2008 Share Posted April 18, 2008 To send a variable using POST you'll need to use a html form. Here's how you would setup the form: <form action="location of the file you want to send the variable to" method="post"> <input type="hidden" value="the variable value" name="formvariable" /> <input type="submit"> </form> Then put this in the receiving document put: <?php $variable=$_POST['formvariable']; ?> But this method of moving a variable between 2 pages involves the viewer clicking on the submit button to send the variable, it would be better if you used GET or SESSION to send the variable. Though you could use Javascript to make the form submit on page load. Link to comment https://forums.phpfreaks.com/topic/101682-passing-variables/#findComment-520215 Share on other sites More sharing options...
nikhar021 Posted April 18, 2008 Author Share Posted April 18, 2008 this way the variable can be passed to only one page i need to pass it to multiple pages Link to comment https://forums.phpfreaks.com/topic/101682-passing-variables/#findComment-520223 Share on other sites More sharing options...
Rowno Posted April 18, 2008 Share Posted April 18, 2008 If you used header("Location: file location here?variable=valuehere"); You could use $_GET['variable'] to retrieve the variable on the first page and then have another header after the script on that page that sends the variable to the second page. Link to comment https://forums.phpfreaks.com/topic/101682-passing-variables/#findComment-520233 Share on other sites More sharing options...
haku Posted April 18, 2008 Share Posted April 18, 2008 You can't pass post variables across two pages automatically. You can add a hidden element to the first page using the value of the post, then pass it to the second page through there, but it will require someone to press a submit button on the second page. Link to comment https://forums.phpfreaks.com/topic/101682-passing-variables/#findComment-520238 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.