dbarak Posted June 17, 2009 Share Posted June 17, 2009 I'm trying to include a PHP file based on whether a variable is set or not. In it's simplest, here's the code I'm trying to use (and I've tried ALL KINDS of things besides this): if (isset($xyz)) { echo $xyz; include("directory/file.php"); } The variable (selected on not selected) is set in a form that then passes that session variable to my script. The session variable is being passed, as it's being echoed on the subsequent page. However, no matter what I do, the include file is ALWAYS displayed, whether the variable is set or not. Any ideas if I'm doing something wrong? From my searches, it looks as if this should be possible. Dave davidabarak@gmail.com Quote Link to comment Share on other sites More sharing options...
reNkai Posted June 17, 2009 Share Posted June 17, 2009 Try testing to see if strlen($xyz) > 0 ? Quote Link to comment Share on other sites More sharing options...
dbarak Posted June 17, 2009 Author Share Posted June 17, 2009 (edited) Hi, and thanks for your answer! Would testing strlen replace isset? In other words (plain language here) if strlen > 0 include the file...? Try testing to see if strlen($xyz) > 0 ? Edited June 17, 2009 by dbarak Quote Link to comment Share on other sites More sharing options...
reNkai Posted June 18, 2009 Share Posted June 18, 2009 yeah it seems to me like that would do it. for some reason your variable is being set. so you'd want to just check if it has a length Quote Link to comment Share on other sites More sharing options...
Jeren Posted June 18, 2009 Share Posted June 18, 2009 You're passing the info from a form. It may seem like a stupid question, but have you already pulled it from the proper super variable? ($_GET or $_POST)? Otherwise, you can't just reference it. Also, if you're using an HTML check box, I found that you really need two fields in your form for it. One is a hidden value with the 'off' value, and then you have your check box AFTER the hidden field that has your 'on' value. Those are just a couple things I thought I'd contribute to this thread. Quote Link to comment Share on other sites More sharing options...
OJB Posted June 18, 2009 Share Posted June 18, 2009 Any chance you can post more of the code, like the HTML form and the PHP which extracts the values from the POST or GET array? When I use checkboxes I personally do something like this: >if(isset($_POST['checkbox-name']) && $_POST['checkbox-name'] == 'on') { //logic here } I personally hate this, I think checkboxes being either 'on' or not passed in the $_POST array is crap, but you deal with what you get. If you are having issues with your $_POST array then debug it with a print_r($_POST) to make sure you are receiving the values you expect. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.