/    Sign up×
Community /Pin to ProfileBookmark

Creating a link using PHP

Hi! I want to create a drop-down menu and let the user select an option. After selecting the option, it will provide a link to another page. But I have problems creating the right link. Take a look at these codes in menu.html:

[CODE]
<form id=”form1″ name=”form1″ method=”post” action=”menu.php”>
Menu
<select name=”Menu” size=”1″ id=”Menu”>
<option value=”option1″>Option 1</option>
<option value=”option2″>Option 2</option>
</select>
<label for=”label”>menu</label>
<input type=”submit” name=”Menu2″ id=”label” value=”Submit” />
</form>[/CODE]

Then, I have another file called menu.php with these codes:

[CODE]
<?php
$selection = $_POST[‘Menu’];
if ( $selection == “option1″) {
<a href=”http://www.<mysite.com/option1.html>”>Option 1</a>
} else if ( $selection == “option2″) {
<a href=”http://www.<mysite.com/option2.html”>Option 2</a>
}
?>[/CODE]

I’m not sure if there is a better way of doing it but the result is not what I expected. I should see Option 1 if the user selects only option1 but now I’m seeing the PHP codes from Option 1 onwards.

Please advise. Many thanks!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@WebnerdSep 20.2007 — <i>
</i>
&lt;?php
$selection = $_POST['Menu'];
if ( $selection == "option1") {
echo '&lt;a href="http://www.mysite.com/option1.html"&gt;Option 1&lt;/a&gt;';
} else if ( $selection == "option2") {
echo '&lt;a href="http://www.mysite.com/option2.html"&gt;Option 2&lt;/a&gt;';
}
?&gt;


You have extra GT/LT signs in your link and you need to echo from PHP
Copy linkTweet thisAlerts:
@firblazerauthorSep 21.2007 — Thanks!
×

Success!

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