Jump to content

Undefined offset 2


mynameisjayson

Recommended Posts

Hi

 

 

I am having undefined offset:2 and any body can give me an idea, why i get this error message.

for($i = 0; $i< count($from_branch) || $i< count($to_branch) || $i< count($quantity) || $i< count($prio_color); $i++)	
									
     {
	$query = mysql_query("INSERT INTO pull_out(`description`,`barcode`,`from`,`to`,quantity,prio_color,date_created,remarks,userid) VALUES('$desc','$barc','$from_branch[$i]','$to_branch[$i]','$quantity[$i]','$prio_color[$i]','$datec','$remar','$userid')");
							
     }

and i use checkbox under prio_color and i think this is the cause, 

Link to comment
https://forums.phpfreaks.com/topic/292184-undefined-offset-2/
Share on other sites

say for example your arrays were as follows

    $from_branch = array(1,2,3);
    $to_branch = array(1,2,3,4);
    $quantity = array(1,2,3,4,5);
    $prio_color = array(1,2,3,4,5,6);

then with your loop $i would be 6

but none of your arrays would have an index of 6 hence the undefined offset.

Link to comment
https://forums.phpfreaks.com/topic/292184-undefined-offset-2/#findComment-1495345
Share on other sites

but i have a correct index from each you suggest.  

<script type="text/javascript">
	var rowNum = 0;
	function addRow(frm) 
			{
				rowNum ++;
				var row = '<p id="rowNum'+rowNum+'"><input type="text" class="form-control" name = "from_branch[]"style = "width:250px;" placeholder="From" value="" required> <input type="text" id="from_2" class="form-control" placeholder="To" style = "width:250px;margin-top:-34px; margin-left:280px;" name = "to_branch[]" value="" required> <input type="text" class="form-control" placeholder="#"style = "width:80px;margin-top:-34px; margin-left:560px;" name = "quantity[]" value="" required> <input type = "checkbox" name = "prio_color[]" value = "#d6f4ca#fd3236" style = "position:absolute;width:80px; margin-top:-23px; margin-left:620px;">  <button type="button" value="Remove" class="btn btn-default" style = "width:40px; margin-top:-57px; margin-left:680px;"onclick="removeRow('+rowNum+');"><span class = "glyphicon glyphicon-minus"></button></p>';
				jQuery('#itemRows').append(row);
				
			}
			function removeRow(rnum) {
			jQuery('#rowNum'+rnum).remove();
			}
		</script>
Link to comment
https://forums.phpfreaks.com/topic/292184-undefined-offset-2/#findComment-1495348
Share on other sites

If prio_color isnt inserting then it means it doesn't have that index you are establishing with your loop.

so you have to either get the array to have that index or change the way you are inserting it.

 

Hard to come up with a solution not knowing what you are trying to accomplish or how you are getting to this point.

Are you just simply trying to add the form results to the DB or something different.

Link to comment
https://forums.phpfreaks.com/topic/292184-undefined-offset-2/#findComment-1495349
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.