473,396 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

include() in if...else statement?

When a user logs in my website, it references a character file. In that character file, there is a variable defined, $guild; which if true, has to include a file with guild information.

So, in the profile page where a user views his/her own information, I need to include the guild file, but since there are more than one guild, I have to include a certain guild file.

I have this so far.

Expand|Select|Wrap|Line Numbers
  1. <?php include('../character_library/'. $_SESSION['name'] .'.inc'); ?>
  2.   <?php
  3.  
  4.     if ($guild == false) {
  5.  
  6.     } else {
  7.  
  8.     include('../character_library/guild_library/'$guild'.inc');
  9.     }
  10. ?>
  11.  
The first part includes the character file, which is in a session when they log in, and the second part needs to include a guild file if they belong to one.

So, in this case, the character does belong to a guild, let's say, the alpha guild.

In the character file it says

Expand|Select|Wrap|Line Numbers
  1. $guild = "alpha";
  2.  
And I have a file on my server called alpha.inc.

When I insert the statement, and later on in the page I try to access $guildmaster which is in the alpha.inc file, it just hangs, and does NOTHING.

Thanks for any help you can give me, I'm a bit of a begginner. :-D

-galadrix
Jun 23 '06 #1
1 8963
Banfa
9,065 Expert Mod 8TB
[php]
include('../character_library/guild_library/'$guild'.inc');
[/php]

I think that you have a small error in this line, I think you need to use the concatinate string operator . , or at least I would so that it looks like

[php]
include('../character_library/guild_library/' . $guild . '.inc');
[/php]

Additionally if the page requires the page I suggest that instead of include you use require. The are 4 functions that includes other files into the current script

include
include_once
require
require_once

The differences are the require functions will produce an error and abort the script if they fail (making it rather obvious). The _once functions (as opposed to the other ones) only include the given file if it has not already been included (useful for files that start sessions and such like).
Jun 25 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: swaroophr | last post by:
Which of switch statement and if-else statement takes less time to execute?
2
by: paul | last post by:
Hi all, I've been handed some code and, unless I've got the numbering of parentheses wrong, one of the functions has a curious if-else statement. The thing compiles but is it right? I know the...
16
by: bitong | last post by:
Just cant figure out how to formulate the correct syntax..I can do it in looping statement but my professor said that use only the simple if-else statement. The problem goes like this..Write a...
2
by: juan-manuel.behrendt | last post by:
Hello together, I wrote a script for the engineering software abaqus/CAE. It worked well until I implemented a selection in order to variate the variable "lGwU" through an if elif, else...
5
by: clear1140 | last post by:
Good day!! I was wondering if it is possible to put an if else statement inside a where clause of an sql statement... you see i would like my update statement to do this: update...
2
by: MicaK | last post by:
Good Morning, I am new to this forum, and extremely new to VBA, so there may be a very simple explanation to this. I also apologize if I am giving you and excessive amount of detail. I have a...
4
by: maveri4201 | last post by:
I have written a php script (test3.php), which I attached as a text file. Its includes are also attached as text files. I'm trying to run the script here: http://www.wondergy.com/phptestbed/test3.php...
6
by: DanicaDear | last post by:
I have this update strSQL that is working great, but I'd like to make it smarter in hopes of preventing input errors. Here is my working code: Else Me.txtScan_Box_Num =...
3
Siddarth777
by: Siddarth777 | last post by:
here am sending u the code of the simple linked list implementation in C language when we go to the append function definition,in the if statement a new node is being created if address of the...
2
by: Robert Ingles | last post by:
I apologize for my current lack of knowledge and hope that someone will be kind enough to give me some additional help.I posted a question regarding "Record does not exist, open add record form". I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.