SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    911
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Weird foreach() error?

    Hi guys,

    I'm currently encountered this weird foreach() error,
    Code:
    A PHP Error was encountered
    Severity: Warning
    Message: Invalid argument supplied for foreach()
    Filename: controllers/admin.php
    Line Number: 391
    And these are the codes that has an error,
    Code:
    			//Process lesson check boxes
    			if(isset($_POST['submitlesson'])) {
    				if(isset($_POST['boxlesson'])) {
    					foreach ($_POST['boxlesson'] as $id){ //This is the error line codes, Line Number: 391
    						echo 'lesson: '. $id .'<br>';
    					}
    				}
    These are the source of the variable $boxlesson,
    Code:
    					<?php
    						//Display lessons records
    						if(!empty($vdata_lessons)) {
    					    	foreach($vdata_lessons as $data) { 
    						    	//$data['lessonid'] $data['namelesson']
    						    	$lesson_url = 'admin/cp_proc/' . $data['lessonid'] . '/lesson/';
    								$lesson_edit_url = 'admin/edit_lessons/' . $data['lessonid'];
    					?>
    								<input type="checkbox" name="boxlesson" value="<?php echo $data['lessonid']; ?>">
    						    	<a href="#">
    						    	<?php
    						    		echo $data['namelesson']. ' ';
    						    	?>
    								</a>
    		        				<a href="<?php echo site_url($lesson_edit_url); ?>">
    		        					<img src="<?php echo base_url('img/icon_edit.png'); ?>" alt="Edit record" height="20" width="20">
    		        				</a>&nbsp;<br>
    					<?php
    					    	}
    						}
    					?>
    Actually the $_POST['boxlesson'] is just a variable name from textboxes inside a form (see above codes).
    What I'm missing?


    Thanks in advance.
    I Love coding...
    Don't click this link.

  2. #2
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    911
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Okay I found the bug,

    I modify the variable name.

    from this,
    Code:
    name="lesson"
    to this,
    Code:
    name="lesson[]"
    Problem solved!

    by myself again. lol
    I Love coding...
    Don't click this link.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •