/    Sign up×
Community /Pin to ProfileBookmark

If….ElseIf…… using Radio Buttons;

I can’t quite figure out what’s wrong here.

[code=php]
if(isset($_POST[‘submit’])||isset($_POST[‘submit’])) {

$selected_radio = $_POST[‘response’];

if ($selected_radio == ‘Page1’) {

header(“url=http://localhost/Test/Page1.php”); }

elseif ($selected_radio == ‘Page2’) {

header(“url=http://localhost/Test/Page2.php”); }

elseif ($selected_radio == ‘Page3’) {

header(“url=http://localhost/Test/Page3.php”); }

elseif ($selected_radio == ‘Page4’) {

header(“url=http://localhost/Test/Page4.php”); }

}
[/code]

And here is my HTML Form :

[code=html]
<form name=”Testing” action=”test.php” method=”post”>
<input type=”radio” name=”response” Value=”Page1″>Page1
<br>
<input type=”radio” name=”response” Value=”Page2″>Page2
<br>
<input type=”radio” name=”response” Value=”Page3″>Page3
<br>
<input type=”radio” name=”response” Value=”Page4″>Page4
<br>
<input type=”submit” name=”submit” value=”Please Select”>
[/code]

When I select a radio button, all I get is re-directed to a BLANK page (the URL in the blank page shows : [B][url]http://localhost/Test/test.php[/url][/B]

Meaning, I am going nowhere.

I can’t figure out what the issue is.

I even inserted an [B]ECHO[/B] statement after each “IF” condition, as follows :

[code=php]if ($selected_radio == ‘Page1’) {

echo “SELECTED PAGE 1” ;

header(“url=http://localhost/Test/Page1.php”); }[/code]

And, I got the ECHO. It showed on the blank screen.

But I was not re-directed to the URL I gave.

I tried to change the URL to the following format : [B]header(‘Location : [url]http://localhost/Test/Page1.php[/url]‘)[/B]

Still nothing.

Any idea what the issue could be ?

Thanks

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 09.2015 — [code=php]
header("Location: http://localhost/Test/Page1.php");
[/code]

Also, it's a good idea to put an [B][COLOR="#0000FF"]exit;[/COLOR][/B] after that, so that nothing else gets processed in the script (assuming at that point you don't [i]want[/i] anything else to be processed?).
Copy linkTweet thisAlerts:
@NogDogMar 09.2015 — PS: You could make the script a bit more portable with:
[code=php]
header("Location http://".$_SERVER['SERVER_NAME']."/Test/Page1.php");
[/code]
Copy linkTweet thisAlerts:
@newuserphpauthorMar 09.2015 — [code=php]
header("Location: http://localhost/Test/Page1.php");
[/code]

Also, it's a good idea to put an [B][COLOR="#0000FF"]exit;[/COLOR][/B] after that, so that nothing else gets processed in the script (assuming at that point you don't [i]want[/i] anything else to be processed?).[/QUOTE]



I already tried that. Didn't work.

Which didn't surprise me. Seeing as nothing is being processed anyway, putting an EXIT at the end didn't change anything.
×

Success!

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