Weiss Posted September 6, 2017 Share Posted September 6, 2017 (edited) Hi. ok ive been working for about 2 hours on 2 lines that for some reason doesnt work. i have a form with 2 inputs: order# and phone#. when user press submit i want it to search the DB. if he entered both phone# and order# the query will be other than if he entered only one of them. so actually i have 4 cases. 1: user submitted without phone# and without order# 2: user submitted with phone# but without order# 3: user submitted without phone# but with order# 4: user submitted with both. can someone help me with the syntax? ive been working on it for freaking hours and it doesnt seem to work. Edited September 6, 2017 by Weiss Link to comment Share on other sites More sharing options...
Weiss Posted September 6, 2017 Author Share Posted September 6, 2017 if (isset($_GET['submit'])){ $flag =1;//1 means both phone# and order# are entered if (!isset($_GET['order_num'])) { if (!isset($_GET['phonesrch'])) {$flag=2;} //means order# isnt set and phonesrch isnt set else{ $flag=3; }//means order# isnt set but phone# is set } else {if (!isset($_GET['phonesrch'])) {flag=4;} //means order# is set, phone# isnt } this is my code but somewhere i guess theres a syntax error Link to comment Share on other sites More sharing options...
Weiss Posted September 6, 2017 Author Share Posted September 6, 2017 one problem i noticed is that if i use if (isset($_GET['phonesrch'])) if (isset($_GET['order_num'])) they ALWAYS return true, even if i submit empty form. why is that? Link to comment Share on other sites More sharing options...
dsonesuk Posted September 6, 2017 Share Posted September 6, 2017 Because even though they are empty, if named input exists on submission it is still set with empty value. To check if set and not empty add !empty() if (isset($_GET['phonesrch']) && !empty($_GET['phonesrch'])) 1 Link to comment Share on other sites More sharing options...
Weiss Posted September 6, 2017 Author Share Posted September 6, 2017 (edited) Yes thank you, realised that just now. do you think there's a better way to attack this other than all this nested if's ? btw, if isset returns true all the time do i still need it? or can i just use the !empty? Edited September 6, 2017 by Weiss Link to comment Share on other sites More sharing options...
dsonesuk Posted September 6, 2017 Share Posted September 6, 2017 Yes, you can use !empty() on its own. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now