Undefined index: x

Posted on 2008-02-11
Medium Priority
Last Modified: 2010-08-05
I ask you if it is safe and enough to add an isset() to $data['x'] in the first line of the snippet
to fix the undefined index error. This is the context:
		foreach ($data['x'] as $fldnum=>$val)
			if($xsubcatfields[$fldnum]['TYPE'] == "N" && !preg_match("/^[0-9]*$/", $val))
				$fldname = $xsubcatfields[$fldnum]['NAME'];
				$numerr .= " &nbsp; - {$fldname}<br />";
	if($numerr) $err .= "&bull; $lang[ERROR_POST_MUST_BE_NUMBER]<br />$numerr";
	if($err) $err = $lang['POST_ERRORS'] . $err;

Open in new window

Question by:jimgordon
LVL 23

Expert Comment

by:Ashish Patel
ID: 20867018
Yes it is safe to use isset function and as to check if $data is defined or undefined you will have to use isset() around the $data variable.
LVL 82

Accepted Solution

hielo earned 2000 total points
ID: 20867026
You would need it at the if:
if(isset($data['x']) && is_array($data['x']))

Author Closing Comment

ID: 31429814
hielo is the best to me

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
I recently worked on a Wordpress site that utilized the popular ContactForm7 (https://contactform7.com/) plug-in that only sends an email and does not save data. The client wanted the data saved to a custom CRM database. This is my solution.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question