php validation. Can't quite wrap my head around the logic I need to happen












0














I have a page, where there are a 3 values passed and the rest of the page will respond based on any of those 3.
if 1 and 2 have values from a form, but 3 and 4 don't { do a } else warn the user to fill out both 1 and 2



if 1 and 2 don't have values, 3 does, 4 doesn't { do b } else warn the user to fill in 3, disregard the state of 1,2 and 4



if 1 and 2 and 3 don't have values, but 4 does { do c } else warn the user to fill in 4, disregard the state of 1,2, and 3



if ($fname != '' and $lname != '') { 
querytype = "name";
} else {
echo "Please enter a first and last name.";
}
if ($reg != '' and $fname == '' and $lname == '') {
$querytype = "reg";
} else {
echo "Please enter a Registration Number.";
}
if ($num != '' and $reg == '' and $fname == '' and $lname == '') {
$querytype = "number";
} else {
echo "Please enter a Phone Number.";
}
switch ($querytype) {
#name is 1 and 2.. it's a first and last name
case "name": {
break;
}
#reg is 3
case "reg":
{
break;
}
#number is 4
case "number":
{
break;
}
default: echo "Something broke.. idk";
}









share|improve this question
























  • What is the problem with your logic now?
    – Jeff
    Nov 12 '18 at 23:59










  • if I input fields 1 and 2.. I still get the errors for 3 and 4
    – Ken Gordon
    Nov 13 '18 at 0:00










  • Because the if condition from the first case is the same as the else from 2nd and 3rd case.
    – Jeff
    Nov 13 '18 at 0:01












  • You'd need to skip the following tests if one is done.
    – Jeff
    Nov 13 '18 at 0:03










  • querytype = "name"; is missing the $ before querytype.
    – Barmar
    Nov 13 '18 at 1:04
















0














I have a page, where there are a 3 values passed and the rest of the page will respond based on any of those 3.
if 1 and 2 have values from a form, but 3 and 4 don't { do a } else warn the user to fill out both 1 and 2



if 1 and 2 don't have values, 3 does, 4 doesn't { do b } else warn the user to fill in 3, disregard the state of 1,2 and 4



if 1 and 2 and 3 don't have values, but 4 does { do c } else warn the user to fill in 4, disregard the state of 1,2, and 3



if ($fname != '' and $lname != '') { 
querytype = "name";
} else {
echo "Please enter a first and last name.";
}
if ($reg != '' and $fname == '' and $lname == '') {
$querytype = "reg";
} else {
echo "Please enter a Registration Number.";
}
if ($num != '' and $reg == '' and $fname == '' and $lname == '') {
$querytype = "number";
} else {
echo "Please enter a Phone Number.";
}
switch ($querytype) {
#name is 1 and 2.. it's a first and last name
case "name": {
break;
}
#reg is 3
case "reg":
{
break;
}
#number is 4
case "number":
{
break;
}
default: echo "Something broke.. idk";
}









share|improve this question
























  • What is the problem with your logic now?
    – Jeff
    Nov 12 '18 at 23:59










  • if I input fields 1 and 2.. I still get the errors for 3 and 4
    – Ken Gordon
    Nov 13 '18 at 0:00










  • Because the if condition from the first case is the same as the else from 2nd and 3rd case.
    – Jeff
    Nov 13 '18 at 0:01












  • You'd need to skip the following tests if one is done.
    – Jeff
    Nov 13 '18 at 0:03










  • querytype = "name"; is missing the $ before querytype.
    – Barmar
    Nov 13 '18 at 1:04














0












0








0







I have a page, where there are a 3 values passed and the rest of the page will respond based on any of those 3.
if 1 and 2 have values from a form, but 3 and 4 don't { do a } else warn the user to fill out both 1 and 2



if 1 and 2 don't have values, 3 does, 4 doesn't { do b } else warn the user to fill in 3, disregard the state of 1,2 and 4



if 1 and 2 and 3 don't have values, but 4 does { do c } else warn the user to fill in 4, disregard the state of 1,2, and 3



if ($fname != '' and $lname != '') { 
querytype = "name";
} else {
echo "Please enter a first and last name.";
}
if ($reg != '' and $fname == '' and $lname == '') {
$querytype = "reg";
} else {
echo "Please enter a Registration Number.";
}
if ($num != '' and $reg == '' and $fname == '' and $lname == '') {
$querytype = "number";
} else {
echo "Please enter a Phone Number.";
}
switch ($querytype) {
#name is 1 and 2.. it's a first and last name
case "name": {
break;
}
#reg is 3
case "reg":
{
break;
}
#number is 4
case "number":
{
break;
}
default: echo "Something broke.. idk";
}









share|improve this question















I have a page, where there are a 3 values passed and the rest of the page will respond based on any of those 3.
if 1 and 2 have values from a form, but 3 and 4 don't { do a } else warn the user to fill out both 1 and 2



if 1 and 2 don't have values, 3 does, 4 doesn't { do b } else warn the user to fill in 3, disregard the state of 1,2 and 4



if 1 and 2 and 3 don't have values, but 4 does { do c } else warn the user to fill in 4, disregard the state of 1,2, and 3



if ($fname != '' and $lname != '') { 
querytype = "name";
} else {
echo "Please enter a first and last name.";
}
if ($reg != '' and $fname == '' and $lname == '') {
$querytype = "reg";
} else {
echo "Please enter a Registration Number.";
}
if ($num != '' and $reg == '' and $fname == '' and $lname == '') {
$querytype = "number";
} else {
echo "Please enter a Phone Number.";
}
switch ($querytype) {
#name is 1 and 2.. it's a first and last name
case "name": {
break;
}
#reg is 3
case "reg":
{
break;
}
#number is 4
case "number":
{
break;
}
default: echo "Something broke.. idk";
}






php conditional






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 1:03









Barmar

419k34244344




419k34244344










asked Nov 12 '18 at 23:50









Ken Gordon

94




94












  • What is the problem with your logic now?
    – Jeff
    Nov 12 '18 at 23:59










  • if I input fields 1 and 2.. I still get the errors for 3 and 4
    – Ken Gordon
    Nov 13 '18 at 0:00










  • Because the if condition from the first case is the same as the else from 2nd and 3rd case.
    – Jeff
    Nov 13 '18 at 0:01












  • You'd need to skip the following tests if one is done.
    – Jeff
    Nov 13 '18 at 0:03










  • querytype = "name"; is missing the $ before querytype.
    – Barmar
    Nov 13 '18 at 1:04


















  • What is the problem with your logic now?
    – Jeff
    Nov 12 '18 at 23:59










  • if I input fields 1 and 2.. I still get the errors for 3 and 4
    – Ken Gordon
    Nov 13 '18 at 0:00










  • Because the if condition from the first case is the same as the else from 2nd and 3rd case.
    – Jeff
    Nov 13 '18 at 0:01












  • You'd need to skip the following tests if one is done.
    – Jeff
    Nov 13 '18 at 0:03










  • querytype = "name"; is missing the $ before querytype.
    – Barmar
    Nov 13 '18 at 1:04
















What is the problem with your logic now?
– Jeff
Nov 12 '18 at 23:59




What is the problem with your logic now?
– Jeff
Nov 12 '18 at 23:59












if I input fields 1 and 2.. I still get the errors for 3 and 4
– Ken Gordon
Nov 13 '18 at 0:00




if I input fields 1 and 2.. I still get the errors for 3 and 4
– Ken Gordon
Nov 13 '18 at 0:00












Because the if condition from the first case is the same as the else from 2nd and 3rd case.
– Jeff
Nov 13 '18 at 0:01






Because the if condition from the first case is the same as the else from 2nd and 3rd case.
– Jeff
Nov 13 '18 at 0:01














You'd need to skip the following tests if one is done.
– Jeff
Nov 13 '18 at 0:03




You'd need to skip the following tests if one is done.
– Jeff
Nov 13 '18 at 0:03












querytype = "name"; is missing the $ before querytype.
– Barmar
Nov 13 '18 at 1:04




querytype = "name"; is missing the $ before querytype.
– Barmar
Nov 13 '18 at 1:04












0






active

oldest

votes











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271768%2fphp-validation-cant-quite-wrap-my-head-around-the-logic-i-need-to-happen%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271768%2fphp-validation-cant-quite-wrap-my-head-around-the-logic-i-need-to-happen%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python