473,698 Members | 2,521 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 40402
On 24 Jun 2004 23:40:31 -0700, kr*****@multime diastudio.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 Projektbetreuun g
http://www.heddesheimer.de/coaching/
Jul 17 '05 #2
"Krishna Srinivasan" <kr*****@multim ediastudio.com> schrieb im Newsbeitrag
news:36******** *************** ***@posting.goo gle.com...
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_exist s('checkbox_nam e', $_GET);
(or $_POST, whatever) to determine whether the variable exists.

--
-- Rudy Fleminger
-- sp@mmers.and.ev il.ones.will.bo w-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
3852
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 positive values in Python 2.4 and up Okay; that's expected. No problem, I'll just turn off the FutureWarning. Here's the results from within an interactive session:
9
12131
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. (State:01003, Native Code: 0) Is there anyway to suppress this message in my report? Thanks
40
7868
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 take a status input, but a certain error-handling state might ignore it: typedef void (*State_Fn)(uint8_t); void error_state(uint8_t status)
3
12406
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 missing debugging information for referencing module; linking object as if no debug info --- I'd like to suppress these warnings and therefor I tried to include a "/ignore 4204" in "Property->Linker->Command Line", unfortunatly
1
4456
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 suppress this warning? Note this is a "PRJ" warning not a "C" (compiler) warning. FYI, my project must include these missing environment variables.
13
9744
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 needed which causes the compiler to spit out a "helpful" warning. For example: % cat unused.c #include <stdio.h> int foo(char *str, void *data) {
3
3790
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 GetCurrentThreadId as we in the testing stages for our product (I have read a few comments about problems just switching to the ManagedThreadId). Does such a pragma id exist, and if so, what is it? Thanks,
10
5421
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 succession one for EACH transfer. Thanks as always :) Tux
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8904
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7741
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.