473,770 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

i am trying to switch array value but i get this error message: Undefined offset 2

i am trying to switch array value but i get this error message: Undefined offset 2

Expand|Select|Wrap|Line Numbers
  1. $at=array(
  2.                           array('Title:','title',2,10),
  3.                           array('First Name:','fname',2,10 ),
i have foreach loop
Expand|Select|Wrap|Line Numbers
  1. foreach($at[$s] as $v){
  2.  
  3. switch ($v[2]){
  4.  
  5. case 2:
  6. if(strlen($_POST[$v[1]]> strlen($_POST($v[2]))   ){
  7. echo 'ok';    
  8.      }else{
  9.         $ok=false;
  10.     }
  11. break;
Nov 7 '10 #1
1 2846
Atli
5,058 Recognized Expert Expert
Line #6 does this $_POST($v[2]).

Two problems:
  1. You should use brackets to fetch array elements, not parenthesis. That is, do: $_POST[$v[2]] instead.
  2. The value of $v[2] in both the examples you posted is 2. - If your $_POST data does not contain a value for a key named "2", you will get the error message you posted.

    You should always use the isset function on input variables before trying to use them. There is always a possibility that they were not sent, and you need to write you code so it can handle that. (That is; output an error message or something.)
Nov 7 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
108841
by: lawrence | last post by:
I just switched error_reporting to ALL so I could debug my site. I got a huge page full of errors. One of the most common was that in my arrays I'm using undefined offsets and indexes. These still work fine, but with error reporting at all they are marked as errors. Why? What am I doing wrong? www.monkeyclaus.org
2
25825
by: Steven | last post by:
Hi All, I am moving some php code from a Linux machine to a Windows 2000 machine with the code belowe I get the following error : Notice: Undefined offset: 1 in c:\inetpub\wwwroot\test.php on line 5 1) reset($kolom1); 2) while(list($cat,$lnk) = each($kolom1)){ 3) kop($cat);
3
3295
by: delusion7 | last post by:
I am getting this error "Undefined offset: 9 in C:\Course Technology\1687-5\Chapter.10\UpdateContactInfo.php on line 36" this is the code I am recieving the error on: if (mysqli_num_rows($QueryResult) > 0) { $Row = mysqli_fetch_row($QueryResult); $First = stripslashes($Row); $Last = stripslashes($Row); $Phone = stripslashes($Row); $Address = stripslashes($Row); $City = stripslashes($Row); $State = stripslashes($Row);
6
4480
by: nicy12 | last post by:
Hi! my name is Peter. iam working on the php platform. while trying to run and compile a program i get the undefined offset error iam nto much familiar with this error . Please help me . Thanks in advance. Error: Undefined offset: 0 in /es/ePrintsStats/includes/inc.html.cumulative_usage.es.php on line 16 The code: <?php $current_year = date("Y"); $last_year = date("Y")-1;
13
4501
by: cfrance1 | last post by:
Hello, I recently started working with access for a school project in my Information Systems Management class. I'm a Finance major so it's not like I had to get this deep into this stuff, but I have a wondering mind. I put together my table and proceeded to creating my queries and they all work fine but one. I have read forum after forum trying to figure out the solution to my problem but no luck I could do without this query but after so...
9
32504
by: simple12 | last post by:
Hello I have a script which have the facility of entering any code to some part of a webpage. I have some problems with it. When i put some code in the script then their is no error shown. When i try to not use a code and leave it empty the following php errors happens. I dont understand why. Help me. Error shown are: - PHP Notice: in file /index.php on line 132: Undefined offset: 4 PHP Notice: in file /index.php on line 141:...
6
6490
by: blackdogharry | last post by:
Hi, I am a novice VBA user. My access version is 2007 on Windows XP PC. I need to create a query that will take pre-existing text values of the B_status field (such as "Received_Emailed", "Processed" etc.) and return the numeric value depending on the value of the B_status value. So I would get 2 in the new field if the value of B_status is "Received_Emailed" and so on. I opened Visual Basic Editor and created a function under...
2
2689
by: neridaj | last post by:
Hello, I'm trying to figure out how to get rid of these errors: Notice: Undefined offset: 1 in output_fns.php on line 315 Notice: getimagesize() : Read error! in output_fns.php on line 315 function get_imgdim()
6
18558
by: raydiamond4u | last post by:
Hello. My name is Raymond. My code is generating the following error: Notice: Undefined offset: 2 in C:\wamp\www\imagegallery\supportfile\include\config.php on line 25 How do i correct the error? Here is the code: <?php // Include file for database connectivity $db_server = "localhost";
1
5157
by: atang | last post by:
Hi, I found the code here, it's excately what i am looking for, ie8 give this error "Notice: Undefined offset: 49 in.." which is this line "if ($num_of_chars==$required)", i'm a newbie, i don't know how to overcome this error, so can someone please help me out? thanks, $string = "one two three"; $word_array = explode(" ",$string); for ($i=count($word_array); $i>=1; $i--) { $word = $i == 1 ? " word" : " words"; echo "Strings containing...
0
9619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10102
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
10038
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
9910
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7460
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
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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

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.