473,387 Members | 1,553 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,387 software developers and data experts.

Suppress notices and warning in code

I have a form with check boxes. When accessing a check box element
that is not checked, I get a notice (Notice: Undefined variable..). Is
there a way to hide these notices and warning in PHP code without
having to modify the PHP.ini file?

Krishna Srinivasan.
Jul 17 '05 #1
6 40381
On 24 Jun 2004 23:40:31 -0700, kr*****@multimediastudio.com (Krishna
Srinivasan) wrote:
I have a form with check boxes. When accessing a check box element
that is not checked, I get a notice (Notice: Undefined variable..). Is
there a way to hide these notices and warning in PHP code without
having to modify the PHP.ini file?


you can enter this line at the top of your code:

error_reporting (E_ALL ^ E_NOTICE);

Regards

Marian

--
Tipps und Tricks zu PHP, Coaching und Projektbetreuung
http://www.heddesheimer.de/coaching/
Jul 17 '05 #2
"Krishna Srinivasan" <kr*****@multimediastudio.com> schrieb im Newsbeitrag
news:36**************************@posting.google.c om...
I have a form with check boxes. When accessing a check box element
that is not checked, I get a notice (Notice: Undefined variable..). Is
there a way to hide these notices and warning in PHP code without
having to modify the PHP.ini file?


You can define which errors will be displayed with the function
error_reporting(). Check the manual for the details. It is a good thing to
write this function at the top of the code, if you use an include file for
db settings and stuff like that, add it there, so you can change it globally
for the whole application.

Anyway it is better to change your code the way that no errors occur:

if(isset($_POST['mycheckbox'])) {
$mycheckbox = $_POST['mycheckbox'];
}
else {
$mycheckbox = "";
}

I usually have error_reporting(E_ALL) for seeing all kinds of warnings and
notices while developing. When going online I change it to
error_reporting(0) to hide errors (that actually should not even occur now,
but you never know...).

HTH
Markus
Jul 17 '05 #3
It's wired how almost immediately after I posted this message I got a
sitepoint tech times newsletter which contained an article on
suppressing these messages.

Thanks for nothing.
Krishna Srinivasan.
Jul 17 '05 #4
Krishna Srinivasan wrote:
I have a form with check boxes. When accessing a check box element
that is not checked, I get a notice (Notice: Undefined variable..). Is
there a way to hide these notices and warning in PHP code without
having to modify the PHP.ini file?

Krishna Srinivasan.


I'd suggest not suppressing the error and rather changing your code to
account for the fact that someone may not check a given box on your
form. The undefined variable notice is much like a compiler warning in
C/C++. Unfortunately, the programmers I deal with in C/C++ ignore the
errors much like you're trying to suppress the PHP notice, which usually
ends up in some type of error further down the road.

Instead, I'd suggest checking for the value before attempting to use it:

if(isset($_POST['var_name']))//User checked the box (sub $_GET if req'd)
{
// Do whatever...
}
else // User didn't check the box
{
// Do whatever... lose the else block if you need to do nothing
}

Any PHP project I manage the first rule is, warnings/notices are errors.
I only allow the suppression of warnings when the warning is dealt
with in the code (for example, I'll usually suppress the warnings from
fopen since my code explicitly deals with failures).

HTH,

Derek
Jul 17 '05 #5
Regarding this well-known quote, often attributed to Krishna Srinivasan's
famous "24 Jun 2004 23:40:31 -0700" speech:
I have a form with check boxes. When accessing a check box element
that is not checked, I get a notice (Notice: Undefined variable..). Is
there a way to hide these notices and warning in PHP code without
having to modify the PHP.ini file?

Krishna Srinivasan.


You could also use
array_key_exists('checkbox_name', $_GET);
(or $_POST, whatever) to determine whether the variable exists.

--
-- Rudy Fleminger
-- sp@mmers.and.evil.ones.will.bow-down-to.us
(put "Hey!" in the Subject line for priority processing!)
-- http://www.pixelsaredead.com
Jul 17 '05 #6
Krishna Srinivasan wrote:
I have a form with check boxes. When accessing a check box element
that is not checked, I get a notice (Notice: Undefined variable..). Is
there a way to hide these notices and warning in PHP code without
having to modify the PHP.ini file?

Krishna Srinivasan.


Have you tried using the "@" symbol when you try to access the variable?
The @ suppresses errors if you put it in front of your code. For instance

@$cat = $_POST['cat'];

would suppress any errors if you couldn't do this.
Jul 17 '05 #7

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

Similar topics

2
by: Terry Carroll | last post by:
If I do the following code, whether in the interactive session or in a file, I get a FutureWarning: >>> x = 0xffffffff <stdin>:1: FutureWarning: hex/oct constants > sys.maxint will return...
9
by: Doug Ly | last post by:
Hi, When I run this query using WinSQL to connect to a DB2 database, it gave me the warning: Error: SQLSTATE 01003: Null values were eliminated from the argument of a column function. ...
40
by: Dave Hansen | last post by:
Please note crosspost. Often when writing code requiring function pointers, it is necessary to write functions that ignore their formal parameters. For example, a state machine function might...
3
by: Philipp Staempfli | last post by:
Hello I have a project which includes different libraries. When I compile the project, I get a huge amount of the following linker warnings: --- warning LNK4204: "C:\...\Debug\vc70.pdb' is...
1
by: Chris Stankevitz | last post by:
My .vcproj references an environment variable that no longer exists: Creating library... Project : warning PRJ0018 : The following environment variables were not found: $(WXWIN) How do I...
13
by: Rex Mottram | last post by:
I'm using an API which does a lot of callbacks. In classic callback style, each routine provides a void * pointer to carry user-defined data. Sometimes, however, the user-defined pointer is not...
3
by: =?Utf-8?B?S2VuRGV2?= | last post by:
I would like to know if there is a pragma id that I can use to suppress the warning I get (.NET 2.0) for the GetCurrentThreadId. I want to use warnings as errors and I don't want to change the...
10
tuxalot
by: tuxalot | last post by:
When changing paths to a BE db located on a network via DoCmd.TransferDatabase is there a way to suppress the macro warning messages that appear? I have 14 tables, and 14 warning messages appear in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.