473,396 Members | 2,076 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.

Trapping Undefined Indicies

Hey, here's some code:

switch ($_GET["content"]) {
case "1":
include("./1_content.html");
break;
case "2":
include("./2_content.html");
break;
default:
echo("nothing!");
}

That works perfectly... But what can I do about having the page not
show undefined index errors if they don't insert ?content= at the end
of the address?

Thanks,
iw****@gmail.com

Jul 23 '05 #1
4 1234
IW****@gmail.com wrote:
Hey, here's some code:

switch ($_GET["content"]) {
case "1":
include("./1_content.html");
break;
case "2":
include("./2_content.html");
break;
default:
echo("nothing!");
}

That works perfectly... But what can I do about having the page not
show undefined index errors if they don't insert ?content= at the end
of the address?

Thanks,
iw****@gmail.com


if (isset($_GET['content']))
switch.....
else .....

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 23 '05 #2
(IW****@gmail.com) decided we needed to hear...
Hey, here's some code:

switch ($_GET["content"]) {
case "1":
include("./1_content.html");
break;
case "2":
include("./2_content.html");
break;
default:
echo("nothing!");
}

That works perfectly... But what can I do about having the page not
show undefined index errors if they don't insert ?content= at the end
of the address?

Thanks,
iw****@gmail.com


use the isset() function to test if $_GET['content'] is set
before you do your switch statement. See
http://www.php.net/manual/en/function.isset.php

--
Dave <da**@REMOVEbundook.com>
(Remove REMOVE for email address)
Jul 23 '05 #3
You guys are the greastest...

Jul 23 '05 #4
IW****@gmail.com wrote:
Hey, here's some code:

switch ($_GET["content"]) {
case "1":
include("./1_content.html");
break;
case "2":
include("./2_content.html");
break;
default:
echo("nothing!");
}


You don't even have to use switch:

if (isset($_GET['content']) &&
file_exists("./{$_GET['content']}_content.html")) {
include "./{$_GET['content']}_content.html";
} else {
print 'Nothing!';
}
JW

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Wugi | last post by:
I'm trying to find an equivalent of key-event trapping which is easy in QBasic. Several of my programs build up a geometric figure with two parameter line families, eg with two nested for..next...
15
by: toylet | last post by:
In most perl examples, it used this method to trap error: open(INFILE, $fname) or die "Unable to open $fname"; process_file(); close(INFILE) other_codes(); Now that if I don't want to die...
8
by: Pete | last post by:
I'm trying to improve my code so that when I open a recordset object, I can absolutely guarantee it is closed and is set = Nothing. I have read some old threads and they all say to use the...
13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
9
by: Keith Briggs | last post by:
How can I trap library calls, say to puts, and get them to call a puts function I write, which then performs some special action before calling the real puts from libc? I tried all kinds of...
2
by: Captain Nemo | last post by:
I'm still using Office 2000 myself, but some of my clients have Office 2003. I've recently added a piece of code to create an instance of Word, open a document, fill in the blanks and become...
45
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
9
by: 47computers | last post by:
Pretty new to PHP, I recently started learning about error trapping. As of right now, I include the following into a page in my website: -------BEGIN PASTE-------- error_reporting(E_ERROR |...
6
by: jsgoodrich | last post by:
I am looking for some help if anyone can lend a hand. I have a simple php website that displays a table from my mysql database. To prep for my MCSE I moved my home server to Windows 2003...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.