/    Sign up×
Community /Pin to ProfileBookmark

Using a select "box" for site navigation

Hello,

I would like to put a select box on my site for navigation purposes. I have seen this done with JavaScript, but I would rather use PHP. The code I wrote dosen’t work and I was wondering if someone in here might tell me why and possibly, how to fix it.
The site is here: [url]http://blackmarketculture.com/artists/jessereno/main.php[/url]

Here’s the broken stuff:

[code=php]

<form method=”post” action=”main.php”>
<select name=”nav” value=”nav”>
<option value=”http://www.pig.com”>PIG</option>
<option value=”http://www.pig.com”>PIG</option>
<option value=”http://www.pig.com”>PIG</option>
<option value=”http://www.pig.com”>PIG</option>
</select>
<input type=”submit” name=”submit” value=”go” />
</form>

<?php
$nav = {$_POST[‘nav’]};
if (isset ($_POST[‘submit’]))
{ header( ‘location: ‘ . $nav ); exit(); } ?>
[/code]

I might also mention that I am using output buffering on this page.
Thanks to anyone who can help…

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 22.2004 — Looks like it's displaying the form, then trying to do the redirect and exiting. header() commands won't function once any output has been sent to the browser. Try moving the code that checks to see if the submit button was clicked and then does the redirect up to the top of the page before any ouput is generated (including plane old HTML markup).
Copy linkTweet thisAlerts:
@Wart_HogauthorDec 23.2004 — Thanks for responding,

I moved the conditional to the top of the page ( right under the ob_start() function). Still no luck though. This one's kind of wierd. I've only been writting in PHP for 6 weeks now and in my experience so far, either the script would work or it would completely fail. This is the first one that "almost" works.

Anyway, thanks again for the suggestion.
Copy linkTweet thisAlerts:
@NogDogDec 23.2004 — Just launched your page again and clicked the "go" button, and if you look closely at the top you see, in black text on almost-black background, this text:
$nav = {$_POST['nav']}; if (isset ($_POST['submit'])) { header( 'location: ' . $nav ); exit(); }[/quote]
This would lead me to believe that maybe you forgot to surround it with <?php...?> tags? ?
Copy linkTweet thisAlerts:
@Wart_HogauthorDec 23.2004 — Thanks for pointing that out. It's hard to tell sometimes with this page, you know with the background being so dark.

I finally got it to work though, I was soooooo relieved. after moving the conditional to the top of the page, It was still acting up. I searched the web for a bit and came across the fix... The concatenation in the header command was a bit screwey, the script I found used:

[code=php]
<?php header ( "location: $var" ); ?>
[/code]


...while I was using:

[code=php]
<?php header ( 'location:' . $var ); ?>
[/code]


I usually make mistakes with the quotes, so I'm not to mad at myself.

Thanks again for helping out, I'm glad there's a resource like this available.
×

Success!

Help @Wart_Hog 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.28,
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,
)...