Jump to content

Infuriating Php If And Include Problem


dbarak

Recommended Posts

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

Link to comment
Share on other sites

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 by dbarak
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...