undefined index

I am getting the error:  Notice: Undefined index: OTHours in /addActivities.php on line 24

Line 24 is the if statement at the beginning of:
    	if ($entry['RegHours']+$entry['OTHours']+$entry['Units'] > 0 ) {
			$sql="Insert Into StaffActivity (StaffID, ActivityID, RegHours, OTHours, Units, ActivityDate) 
					values ('".$entry['StaffID']."',".$entry['ActivityID'].",".
							$entry['RegHours'].",".$entry['OTHours'].",".
							$entry['Units'].",'".$_POST['activityDate']."')";
			$outputResult=$sql;
	    	if (!$res = mysql_query($sql)) die( mysql_error() );
    	}

Open in new window


however, the insert is working perfectly and I count the number of OTHours in the document and it matches the count of RegHours and Units.  In fact, the form is built dynamically and there is always an OTHours for every RegHours.

Any idea what could be happening?
LVL 7
UniqueDataAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Marco GasiFreelancerCommented:
I suspect that code is within another loop (something like in the other question). Usually, this kind of errors is because php try to loop one more time over the total amount of rows: can you show the loop, if there is one?
0
Ray PaseurCommented:
Let's go with this as being line 24:

if ($entry['RegHours']+$entry['OTHours']+$entry['Units'] > 0 ) {

Just before that statement, put in this line:

var_dump($entry);

Then you can see what keys and data are present inside the $entry array
0
UniqueDataAuthor Commented:
interesting.  The var_dump stops at:
["5f79aa69a56bf82ec8dbf4fddb94062058"]=>
    array(5) {
      ["StaffID"]=>
      string(2) "71"
      ["ActivityID"]=>
      string(2) "58"
      ["Units"]=>
      string(0) ""
      ["RegHours"]=>
      string(0) ""
      ["OTHours"]=>
      string(0) ""
    }
    ["5f79aa69a56bf82ec8dbf4fddb94062059"]=>
    array(4) {
      ["StaffID"]=>
      string(2) "71"
      ["ActivityID"]=>
      string(2) "59"
      ["Units"]=>
      string(0) ""
      ["RegHours"]=>
      string(0) ""
    }
  }

Open in new window


notice that ActivityID 58 has all 5 elements while ActivityID only has 4 (it is missing the OT).
However, when I look at the source for the page I see:
<td>
	<input type='hidden' name='entry[5f79aa69a56bf82ec8dbf4fddb94062058][StaffID]' value='71'>
	<input type='hidden' name='entry[5f79aa69a56bf82ec8dbf4fddb94062058][ActivityID]' value='58'>
	<input class='unitVal' type='text' name='entry[5f79aa69a56bf82ec8dbf4fddb94062058][Units]' size='4'>
</td>
<td>
	<input class='regVal' type='text' name='entry[5f79aa69a56bf82ec8dbf4fddb94062058][RegHours]' size='4'>
</td>
<td>
	<input class = 'otVal' type='text' name='entry[5f79aa69a56bf82ec8dbf4fddb94062058][OTHours]' size='4'>
</td>
<td>
	<input type='hidden' name='entry[5f79aa69a56bf82ec8dbf4fddb94062059][StaffID]' value='71'>
	<input type='hidden' name='entry[5f79aa69a56bf82ec8dbf4fddb94062059][ActivityID]' value='59'>
	<input class='unitVal' type='text' name='entry[5f79aa69a56bf82ec8dbf4fddb94062059][Units]' size='4'>
</td>
<td>
	<input class='regVal' type='text' name='entry[5f79aa69a56bf82ec8dbf4fddb94062059][RegHours]' size='4'>
</td>
<td>
	<input class = 'otVal' type='text' name='entry[5f79aa69a56bf82ec8dbf4fddb94062059][OTHours]' size='4'>
</td>
<td>
	<input type='hidden' name='entry[5f79aa69a56bf82ec8dbf4fddb94062060][StaffID]' value='71'>
	<input type='hidden' name='entry[5f79aa69a56bf82ec8dbf4fddb94062060][ActivityID]' value='60'>
	<input class='unitVal' type='text' name='entry[5f79aa69a56bf82ec8dbf4fddb94062060][Units]' size='4'>
</td>
<td>
<input class='regVal' type='text' name='entry[5f79aa69a56bf82ec8dbf4fddb94062060][RegHours]' size='4'>
</td>
<td>
<input class = 'otVal' type='text' name='entry[5f79aa69a56bf82ec8dbf4fddb94062060][OTHours]' size='4'>
</td>

Open in new window

and so on.  But no entries after this Activity 59 are getting submitted.  I don't see anything wrong with the html  (note, I added the carriage returns in the html to make it readable.  My loops just put it all together in one line.

Here is my looping code:
		          <tbody>
          		<?php 
          			while($resUsers = mysql_fetch_array($rstUsers)) {
          				echo "<tr>";
          				echo "<td class='nameColumn'>".$resUsers['LastName'].', '.$resUsers['FirstName']."</td>";
						mysql_data_seek($rstActivities, 0) ;      					
  						while($row = mysql_fetch_assoc($rstActivities))
      					{
							echo "<td>";
								// $resUsers['uuk'].$row['ActivityID'] creates a unique id instead of keeping a loop counter
								echo "<input type='hidden' name='entry[".$resUsers['uuk'].$row['ActivityID']."][StaffID]' value='".$resUsers['_key']."'>";
								echo "<input type='hidden' name='entry[".$resUsers['uuk'].$row['ActivityID']."][ActivityID]' value='".$row['ActivityID']."'>";
								echo "<input class='unitVal' type='text' name='entry[".$resUsers['uuk'].$row['ActivityID']."][Units]' size='4'>";
							echo "</td>";
							echo "<td><input class='regVal' type='text' name='entry[".$resUsers['uuk'].$row['ActivityID']."][RegHours]' size='4'></td>";
							echo "<td><input class = 'otVal' type='text' name='entry[".$resUsers['uuk'].$row['ActivityID']."][OTHours]' size='4'></td>";						
						}      					

					echo "</tr>";
					}
				?>
	            </tbody>  

Open in new window

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Ray PaseurCommented:
Well, it "smells" like a logic error, and I don't think I can debug that based on the code - we would need to see all the data and test cases, too.  Something is going missing, and with inputs of type=text, there should always be a field present - perhaps empty, but always a defined index.  Perhaps step through it a line at a time and check to see where the OTHours index is used (case-sensitive).

In semi-related news, you probably want to be aware of this:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
UniqueDataAuthor Commented:
I know how to step through vba code, but how do you step through php/html?
0
UniqueDataAuthor Commented:
I excluded that one staff record and now the next staff ID has the issue.  
I then excluded the Activity it was hanging up on and it still didn't work.
It is always at the same point:

array(2) {
  ["activityDate"]=>
  string(10) "2015-03-11"
  ["entry"]=>
  array(200) {
    ["0b840da71056d6fe56d78bf6f8f9169c13"]=>
    array(5) {

Open in new window


am I hitting some max of an array and it can't create any more?  It always stops at array(200) with the final array of 4. I  googled array limits and it seems to be a huge number.
0
Ray PaseurCommented:
You're not hitting an array limit.  There is probably something in the program logic that is creating a limit.  Here is how I would try to deconstruct the problem.

First, find the query that generates the $rstUsers results set.  Pull this out into its own script.  You will want to remove all of the other elements and just run this query so you can understand the results.  You can run the query, then retrieve the results set and inspect all of the rows with var_dump().  There may be some obvious clues (or not) but at least you will be able to prove to yourself that it's not the query that is the cause of the problem.

After that, begin to rebuild the application a piece at a time using the query results set.  As you put the parts back together you can test each step, step-by-step, to see where the logic error intrudes.  It's a lengthy process but it's the price we pay to become successful developers.  If you choose to turn toward Test Driven Development, you'll start getting faster results almost immediately!  Highly recommended.
0
UniqueDataAuthor Commented:
Ahhhh.  

So when I just get all the users I get a var_dump with an array of 35.  That is all the staff.
when I get only the activities I get an array of 74.  That is the correct number of Activities.  So the end result should be an array of 35*74.
when I put all the fields back in it always stopped at an array of 200, each containing an array of 5.  I took out one input box and got an array of 250, each containing an array of 4.  I took out one more and got an array of 334, each containing an array of 3, except the last only had an array of 1.  
Doing the math they all added up to 1000.  I then googled php array 1000 and found all kinds of posts about that being the limit and needing to edit the php.ini file.  one example:  https://anothersysadmin.wordpress.com/2012/02/16/php-5-3-max_input_vars-and-big-forms/

 I have my site hosted on Surpass Hosting and I need to research if I can edit that ini file.  

Another post suggested something called Stringify.  I will need to research unless there is a better fix.
0
Ray PaseurCommented:
You should ask your hosting company, for sure.  They may be using "Suhosin" or some similar software add-on that can cripple PHP's abilities (they call this "security," but it's just a nuisance).

You may want to run phpinfo() and scan the output for the string "max" since there are some PHP limits that can be in play.  You may also want to get a professional programmer to take a look at the application.  If you're hitting the maximum input limits there is something wrong in the overall design.  My general recommendation (without having studied your specific situation) would be to put those large data collections into a database, and send just the database keys that would be needed to recover the data.
0
UniqueDataAuthor Commented:
Since I don't know how many people are going to be in the staff table, and even the activity record count could go up eventually, I should probably come up with a way that can handle more array items without editing the ini file.  I will research stringify or other options for sending the data to a php file.

One thing, they will not be entering activities for every staff for every activity, so I am thinking I need to loop through anything that has a qty, regHours, or otHours and only send those records.  I do that in the post code already, but that is after everything tries to get shoved into the POST :)
0
UniqueDataAuthor Commented:
I am trying stringify but not getting very far.  I have posted another question:
    http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28636104.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
UniqueDataAuthor Commented:
The initial issue was that I was hitting the upper limit of the array.  The work-around was provided in my other question.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

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.