Back to Top
The nuts and bolts for
Creative web development

PHP - Getting notice Undefined index

Question:
I am getting the following message: Notice: Undefined index: action in /home/fhlinux170/c/cybernet-designs.co.uk/user/htdocs/formtest.php on line 17.

Line 17 contains this line of code if($_POST['action'] == "send"){

Answer:
This error appears because of your PHP error reporting settings. Usually, it appears when your variable is not properly set. There are two ways to handle this issue:

1. Check if $_POST['action'] is set before using it. For example:

if (!isset($_POST['action']))
{
//If not isset -> set with dumy value
$_POST['action'] = "undefine";
}

2. Suppress Notice warnings

Notice warnings could be suppressed by changing the error_reporting variable in your PHP.ini. error_reporting could be set to show all errors except those for notices and coding standards warnings: error_reporting = E_ALL & ~E_NOTICE

The same is accomplished by adding the following line in your php page:

<?php error_reporting (E_ALL ^ E_NOTICE); ?>

Georgi Kralev

Georgi Kralev is a native of Bulgaria and graduated from Technical University Sofia with a Master’s Degree in Computer systems and technologies.

Starting his professional career as desktop developer at Delphi, he moved into the field of .NET development (ASP.NET, windows forms, console applications, windows services, and web services). He also has experience with the following technologies: classical ASP, PHP, HTML / DHTML, XML, JavaScript).

He has received the EUR ING professional title from the European Federation of National Engineering Associations (FEANI)

He has achieved the following professional certificates:
• Microsoft Certified Professional Developer (MCPD) Enterprise Application Developer and Microsoft Certified Professional.
• Several Brainbench certificates in software development.
• Cisco Certified Network Associate

Personal web site for C# and .NET programming:
http://gdkralev.googlepages.com

See All Postings From Georgi Kralev >>

Share this Article