Jump to content

how can i remove the notice ....


lovefek

Recommended Posts

hello everyone,i was just trying to test the php page i've designed some time before but i get a notice that is being displayed on the page which goes: Notice: Undefined index: id in C:\webroot\admin\home.php on line 4i have seen the code on line 4. its just the following: $vid=$_GET["id"];well, when the page runs for the first time there will not be any value for id to be transfered. Could that be the reason or something else. by the way it works when i test it locally. am not sure whether its because of the php.ini file definition in the case of my webserver. am not authorized to change the server's php.ini file definition. anyone with the solution is highly appreciated..thank a lot

Link to comment
Share on other sites

It is in fact because the get variable is not defined. The only way to not show this is to turn off error reporting. There is a function for it, go to php.net and search for error_reporting in the function list.

Link to comment
Share on other sites

There is always a way to avoid a notice or warning. But PHP is lax enough that most people ignore them. Good programmers will write code that will not display any warnings or notices, even if E_ALL is being reported. Test if the variable is defined before you use it.

if (isset($_GET['id']))  $id = $_GET['id'];else  $id = "";

or:

if (!isset($_GET['id']))  $_GET['id'] = "";$id = $_GET['id'];

You can use this to cause PHP to only report runtime errors, warnings, and parse errors:error_reporting(E_ERROR | E_WARNING | E_PARSE);

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...