Radio buttons give wrong value in php
So, I am trying to make a login + register page in-one. Where I use radio buttons to get the value if you want to login or register.
Here is the radio button s code;
<div class="form-check">
<input class="form-check-input" type="radio" name="check" id="check" value="1">
<label class="form-check-label" for="check">Register</label>
<br>
<input class="form-check-input" type="radio" name="check" id="check" value="0" checked>
<label class="form-check-label" for="check">Login</label>
</div>
So, I am checking for $_POST['check']
if the value is 0
or 1
. But somehow it just ignores that, and always registers. Here is my php code;
session_start();
if (isset($_POST['username'])) {
$value = $_POST['check'];
// Do some stuff here
if ($value == 1) {
// register
} elseif ($value == 0) {
// login
} else {
// Do something for bad results
}
}
Somehow when I check login
it wants to register, but when I click on register, it still registers. Something is going wrong here right?
php html forms session
|
show 3 more comments
So, I am trying to make a login + register page in-one. Where I use radio buttons to get the value if you want to login or register.
Here is the radio button s code;
<div class="form-check">
<input class="form-check-input" type="radio" name="check" id="check" value="1">
<label class="form-check-label" for="check">Register</label>
<br>
<input class="form-check-input" type="radio" name="check" id="check" value="0" checked>
<label class="form-check-label" for="check">Login</label>
</div>
So, I am checking for $_POST['check']
if the value is 0
or 1
. But somehow it just ignores that, and always registers. Here is my php code;
session_start();
if (isset($_POST['username'])) {
$value = $_POST['check'];
// Do some stuff here
if ($value == 1) {
// register
} elseif ($value == 0) {
// login
} else {
// Do something for bad results
}
}
Somehow when I check login
it wants to register, but when I click on register, it still registers. Something is going wrong here right?
php html forms session
1
And what will change?
– Oleg Nurutdinov
Nov 26 '18 at 9:38
2
@Twinkle1 == "1"
is true in PHP
– Cid
Nov 26 '18 at 9:38
2
You can var_dump($_POST['check']) to find out what you are receiving
– Gasanov
Nov 26 '18 at 9:39
2
I tried your code and I have the expected result.$value
might be overwritten in the// Do some stuff here
. This is by the way a very bad naming which can lead to confusion/overwritting.
– Cid
Nov 26 '18 at 9:47
1
I agree with user @Cid; tested your code as is and it worked as intended for me. Perhaps posting more code may be appropriate to identify the issue.
– cmprogram
Nov 26 '18 at 9:54
|
show 3 more comments
So, I am trying to make a login + register page in-one. Where I use radio buttons to get the value if you want to login or register.
Here is the radio button s code;
<div class="form-check">
<input class="form-check-input" type="radio" name="check" id="check" value="1">
<label class="form-check-label" for="check">Register</label>
<br>
<input class="form-check-input" type="radio" name="check" id="check" value="0" checked>
<label class="form-check-label" for="check">Login</label>
</div>
So, I am checking for $_POST['check']
if the value is 0
or 1
. But somehow it just ignores that, and always registers. Here is my php code;
session_start();
if (isset($_POST['username'])) {
$value = $_POST['check'];
// Do some stuff here
if ($value == 1) {
// register
} elseif ($value == 0) {
// login
} else {
// Do something for bad results
}
}
Somehow when I check login
it wants to register, but when I click on register, it still registers. Something is going wrong here right?
php html forms session
So, I am trying to make a login + register page in-one. Where I use radio buttons to get the value if you want to login or register.
Here is the radio button s code;
<div class="form-check">
<input class="form-check-input" type="radio" name="check" id="check" value="1">
<label class="form-check-label" for="check">Register</label>
<br>
<input class="form-check-input" type="radio" name="check" id="check" value="0" checked>
<label class="form-check-label" for="check">Login</label>
</div>
So, I am checking for $_POST['check']
if the value is 0
or 1
. But somehow it just ignores that, and always registers. Here is my php code;
session_start();
if (isset($_POST['username'])) {
$value = $_POST['check'];
// Do some stuff here
if ($value == 1) {
// register
} elseif ($value == 0) {
// login
} else {
// Do something for bad results
}
}
Somehow when I check login
it wants to register, but when I click on register, it still registers. Something is going wrong here right?
php html forms session
php html forms session
edited Nov 26 '18 at 13:35
Funk Forty Niner
1
1
asked Nov 26 '18 at 9:34
minecraft accountminecraft account
13
13
1
And what will change?
– Oleg Nurutdinov
Nov 26 '18 at 9:38
2
@Twinkle1 == "1"
is true in PHP
– Cid
Nov 26 '18 at 9:38
2
You can var_dump($_POST['check']) to find out what you are receiving
– Gasanov
Nov 26 '18 at 9:39
2
I tried your code and I have the expected result.$value
might be overwritten in the// Do some stuff here
. This is by the way a very bad naming which can lead to confusion/overwritting.
– Cid
Nov 26 '18 at 9:47
1
I agree with user @Cid; tested your code as is and it worked as intended for me. Perhaps posting more code may be appropriate to identify the issue.
– cmprogram
Nov 26 '18 at 9:54
|
show 3 more comments
1
And what will change?
– Oleg Nurutdinov
Nov 26 '18 at 9:38
2
@Twinkle1 == "1"
is true in PHP
– Cid
Nov 26 '18 at 9:38
2
You can var_dump($_POST['check']) to find out what you are receiving
– Gasanov
Nov 26 '18 at 9:39
2
I tried your code and I have the expected result.$value
might be overwritten in the// Do some stuff here
. This is by the way a very bad naming which can lead to confusion/overwritting.
– Cid
Nov 26 '18 at 9:47
1
I agree with user @Cid; tested your code as is and it worked as intended for me. Perhaps posting more code may be appropriate to identify the issue.
– cmprogram
Nov 26 '18 at 9:54
1
1
And what will change?
– Oleg Nurutdinov
Nov 26 '18 at 9:38
And what will change?
– Oleg Nurutdinov
Nov 26 '18 at 9:38
2
2
@Twinkle
1 == "1"
is true in PHP– Cid
Nov 26 '18 at 9:38
@Twinkle
1 == "1"
is true in PHP– Cid
Nov 26 '18 at 9:38
2
2
You can var_dump($_POST['check']) to find out what you are receiving
– Gasanov
Nov 26 '18 at 9:39
You can var_dump($_POST['check']) to find out what you are receiving
– Gasanov
Nov 26 '18 at 9:39
2
2
I tried your code and I have the expected result.
$value
might be overwritten in the // Do some stuff here
. This is by the way a very bad naming which can lead to confusion/overwritting.– Cid
Nov 26 '18 at 9:47
I tried your code and I have the expected result.
$value
might be overwritten in the // Do some stuff here
. This is by the way a very bad naming which can lead to confusion/overwritting.– Cid
Nov 26 '18 at 9:47
1
1
I agree with user @Cid; tested your code as is and it worked as intended for me. Perhaps posting more code may be appropriate to identify the issue.
– cmprogram
Nov 26 '18 at 9:54
I agree with user @Cid; tested your code as is and it worked as intended for me. Perhaps posting more code may be appropriate to identify the issue.
– cmprogram
Nov 26 '18 at 9:54
|
show 3 more comments
1 Answer
1
active
oldest
votes
id
of element must be unique
code should look like this
<div class="form-check">
<input class="form-check-input" type="radio" name="check" id="check_1" value="1">
<label class="form-check-label" for="check_1">Register</label>
<br>
<input class="form-check-input" type="radio" name="check" id="check_0" value="0" checked>
<label class="form-check-label" for="check_0">Login</label>
</div>
Although this is fixing an invalid HTML, this has nothing to do with the problem.
– Cid
Nov 26 '18 at 9:50
point of problem may be at the last line of this question
– EK LY
Nov 26 '18 at 10:02
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53478187%2fradio-buttons-give-wrong-value-in-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
id
of element must be unique
code should look like this
<div class="form-check">
<input class="form-check-input" type="radio" name="check" id="check_1" value="1">
<label class="form-check-label" for="check_1">Register</label>
<br>
<input class="form-check-input" type="radio" name="check" id="check_0" value="0" checked>
<label class="form-check-label" for="check_0">Login</label>
</div>
Although this is fixing an invalid HTML, this has nothing to do with the problem.
– Cid
Nov 26 '18 at 9:50
point of problem may be at the last line of this question
– EK LY
Nov 26 '18 at 10:02
add a comment |
id
of element must be unique
code should look like this
<div class="form-check">
<input class="form-check-input" type="radio" name="check" id="check_1" value="1">
<label class="form-check-label" for="check_1">Register</label>
<br>
<input class="form-check-input" type="radio" name="check" id="check_0" value="0" checked>
<label class="form-check-label" for="check_0">Login</label>
</div>
Although this is fixing an invalid HTML, this has nothing to do with the problem.
– Cid
Nov 26 '18 at 9:50
point of problem may be at the last line of this question
– EK LY
Nov 26 '18 at 10:02
add a comment |
id
of element must be unique
code should look like this
<div class="form-check">
<input class="form-check-input" type="radio" name="check" id="check_1" value="1">
<label class="form-check-label" for="check_1">Register</label>
<br>
<input class="form-check-input" type="radio" name="check" id="check_0" value="0" checked>
<label class="form-check-label" for="check_0">Login</label>
</div>
id
of element must be unique
code should look like this
<div class="form-check">
<input class="form-check-input" type="radio" name="check" id="check_1" value="1">
<label class="form-check-label" for="check_1">Register</label>
<br>
<input class="form-check-input" type="radio" name="check" id="check_0" value="0" checked>
<label class="form-check-label" for="check_0">Login</label>
</div>
answered Nov 26 '18 at 9:43
EK LYEK LY
2715
2715
Although this is fixing an invalid HTML, this has nothing to do with the problem.
– Cid
Nov 26 '18 at 9:50
point of problem may be at the last line of this question
– EK LY
Nov 26 '18 at 10:02
add a comment |
Although this is fixing an invalid HTML, this has nothing to do with the problem.
– Cid
Nov 26 '18 at 9:50
point of problem may be at the last line of this question
– EK LY
Nov 26 '18 at 10:02
Although this is fixing an invalid HTML, this has nothing to do with the problem.
– Cid
Nov 26 '18 at 9:50
Although this is fixing an invalid HTML, this has nothing to do with the problem.
– Cid
Nov 26 '18 at 9:50
point of problem may be at the last line of this question
– EK LY
Nov 26 '18 at 10:02
point of problem may be at the last line of this question
– EK LY
Nov 26 '18 at 10:02
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53478187%2fradio-buttons-give-wrong-value-in-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
And what will change?
– Oleg Nurutdinov
Nov 26 '18 at 9:38
2
@Twinkle
1 == "1"
is true in PHP– Cid
Nov 26 '18 at 9:38
2
You can var_dump($_POST['check']) to find out what you are receiving
– Gasanov
Nov 26 '18 at 9:39
2
I tried your code and I have the expected result.
$value
might be overwritten in the// Do some stuff here
. This is by the way a very bad naming which can lead to confusion/overwritting.– Cid
Nov 26 '18 at 9:47
1
I agree with user @Cid; tested your code as is and it worked as intended for me. Perhaps posting more code may be appropriate to identify the issue.
– cmprogram
Nov 26 '18 at 9:54