/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Maintain $_POST value across pages

I am trying to print the topics from a phpbb forum, filtered first by category then by forum.
I am using this form to select the category

[code]
<form id=”category” method=”post” action=”forumtext.php”>
<select name=”category” size=”1″ style=”width: 30em”>
<?php$sql=”select cat_title FROM phpbb_categories”;
$rs=mysql_query($sql,$conn);
while($row=mysql_fetch_array($rs)){
echo(“<option>” . $row[‘cat_title’] .”</option>”);
}
?>
</select></p><p>
<input type=”submit” value=”Request Report”></p>
</form>[/code]

Then I am passing that choice to another form to select the forum from within the category

[code]
<form id=”forum” method=”post” action=”forumtextout.php”>
<select name=”forum” size=”1″ style=”width: 20em”>
$sql=”select forum_name FROM phpbb_forums left join phpbb_categories on phpbb_forums.cat_id=phpbb_categories.cat_id WHERE cat_title=’$_POST[category]’ ORDER BY forum_name”;

$rs=mysql_query($sql,$conn);
while($row=mysql_fetch_array($rs)) {
echo (“<option>” . $row[‘forum_name’] .”</option>”);
}
?>
</select><p>
<input type=”submit” value=”Request Post Report”></p></form>
[/code]

That is where I am lost.
The page “forumtextout.php”

[code]
<h1><?php $_POST[‘category’] ?></h1>
<?php
$msg = $_POST[‘forum’];
echo “<p>The forum you selected is ” . $msg . “</p>”;
?>[/code]

returns an error “Undefined index: category”.
Can I maintain the value of $_POST[category] onto the second page?

Thanks,

Andy

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Feb 10.2007 — In your second form, you need to define:[code=php]<input type='hidden' name='category' value='<?php echo $_POST['category'] ?>'>";[/code]
Copy linkTweet thisAlerts:
@1andywauthorFeb 10.2007 — Works like a charm. Thank you, nightshift.

Andy
Copy linkTweet thisAlerts:
@decibelFeb 10.2007 — for multiple items

while(list($key, $value) = each($_POST)){

echo '<input type="hidden" name="$key" value="$value" />';

}

your escaping might be different, but the concept should be clear
Copy linkTweet thisAlerts:
@NightShift58Feb 10.2007 — Yes, that would work but in that form, there's only one post variable.
Copy linkTweet thisAlerts:
@decibelFeb 11.2007 — ive made it a habit to use it by default, i mean even if the form im using only needs on thing passed, if i ever need to upgrade the form, the code is already there, and its just as easy to add
×

Success!

Help @1andyw spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...