473,414 Members | 1,675 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Warning: Invalid argument supplied for foreach()

no check box selected when i gave delete all link the error is coming


Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  include "includes/connection.php";
  4.  include "includes/Functions_category.php";
  5.  include "includes/functions_db.php";
  6.  $Strtitle="Category Management (Category Listing)";
  7.  $strAddedDate=date("Y-m-d h:m:s");
  8.  
  9.     if($_POST['frmcheckall']){    
  10.        print doDeleteAll($_POST);
  11.  
  12.    }
  13.        if(isset($_GET['id'])){
  14.     //if($_POST['id']){
  15.     //$strDelete=doDeleteAll['id'];
  16.    // }
  17.     if(!doDelete($_GET['id'])){$strMessage= "Invalid Inputs Detected!";}
  18.    }
  19.  
  20.  
include"includes/pagestart.php"; ?>

Expand|Select|Wrap|Line Numbers
  1.  
  2. <link href="css/fonts.css" rel="stylesheet" type="text/css">
  3. <script type="text/javascript">
  4. function checkAll(field){
  5.  field=document.frmcategory.frmcheckall;
  6.  for (i = 0; i < field.length; i++){
  7.  field[i].checked = true;
  8.  highlightRow('frmcheckall'+i,'frmcheck'+i);
  9.  }
  10.  }
  11. function uncheckAll(field){
  12.  field=document.frmcategory.frmcheckall;
  13.  for (i = 0; i < field.length; i++){
  14.  field[i].checked = false;
  15.  highlightRow('frmcheckall'+i,'frmcheck'+i);
  16.  }
  17.  }
  18. /*function deleteall(field){
  19.  
  20.     field=document.frmcateogry.frmcheckall;
  21.  flag=0;
  22.  for(i=0;i< field.length;i++){
  23.  
  24.   if(field[i].checked)
  25.   flag=1;
  26.   }
  27.  if(flag==1){
  28.    alert("Hi");
  29.    document.frmcateogry.frmcheckall.submit();
  30.  }else
  31.    alert("Please select one category to Delete");
  32.  }*/
  33.  function deleted(field){
  34.  //field=document.frmcategory.frmcheckall;
  35.   flag=0;
  36.   for(i=0;i< field.length;i++){
  37.    if(field[i].checked)
  38.    flag=1;
  39.   }
  40.  
  41.   if(flag==1){
  42.    if(confirm("Are You Sure To Delete The Category List?")){
  43.    field.submit();
  44.    }
  45.   }else
  46.    alert("Please Select One Category To DELETE");
  47.  }
  48.  function highlightRow(id,id1) { //alert(id1);
  49.  
  50.   if (document.getElementById(id).checked) {
  51.  
  52.    document.getElementById(id1).bgColor = '#E2E6A8';
  53.   }
  54.   else {
  55.  
  56.    document.getElementById(id1).bgColor = '#FFFFFF';
  57.   }
  58.   }
  59.  
  60. function deleteConfirm(delUrl) {
  61.   if (confirm("Are You Sure To Delete This Category?")) {
  62.     document.location = delUrl;
  63.     }
  64.   }
  65. </script>
  66. <form name="frmcategory" method="post" action="">
  67.  
  68.   <table width="90%" border="0" cellspacing="3" cellpadding="3" align="center">
  69.   <tr><td><? print $strMessage ;?></td></tr>
  70.     <tr>
  71.       <td align="center">
  72.         <?
  73.   $strQuery="select * from tbl_categories where IsDeleted='No'";
  74.   $strValue=SelectQry($strQuery);
  75.    if(is_array($strValue)){
  76.    ?>
  77.         <span class="tablehead">Category List</span></td>
  78.     </tr>
  79.   </table>
  80.   <div align="center">&nbsp;
  81.     <table width="414" height="20" border="0" cellpadding="0" cellspacing="0" class="size">
  82.       <tr>
  83.         <td width="414" class="headerfont"><a href="javascript:onclick=checkAll();" class="headerfont">SELECT
  84.           ALL | </a><a href="javascript:onclick=uncheckAll();" class="headerfont">UNSELECT
  85.           ALL </a>| <a href="javascript:onclick=deleted(frmcategory);" class="headerfont">DELETE
  86.           SELECTED </a></td>
  87.       </tr>
  88.     </table>
  89.   </div>
  90.   <table width="421" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#999999" class="headerfont" style="border-collapse:collapse">
  91.     <tr class="tablehead">
  92.       <td width="44" height="29">&nbsp;</td>
  93.       <td width="278" align="center">CATEGORY NAME </td>
  94.       <td width="179" align="center">ACTION </td>
  95.     </tr>
  96.     <?
  97.  //while($rows = mysql_fetch_object($stredit)){
  98.  for($i=0;$i<count($strValue);$i++) {
  99.   ?>
  100.     <tr class="tablehead" id="frmcheck<?php print $i; ?>">
  101.       <td height="25" align="center"><input name="frmcheckall" type="checkbox" id="frmcheckall<?php print $i; ?>" value="<? print $strValue[$i]['CategoryId']; ?>" onclick="highlightRow('frmcheckall<?php print $i; ?>','frmcheck<?php print $i; ?>');" />
  102.       </td>
  103.       <td class="tablecontent"><? print $strValue[$i]['CategoryName']; ?></td>
  104.       <td align="center" class="tablecontent"><a href="edit.php?id=<? print $strValue[$i]['CategoryId']; ?>">Edit</a>
  105.         | <a href="javascript:deleteConfirm('cateogrylist.php?id=<? print $strValue[$i]['CategoryId']; ?>')">Delete
  106.         </a> </td>
  107.     </tr>
  108.     <?
  109.  }
  110. //mysql_free_result($stredit);
  111. ?>
  112.     <tr align="left" class="tablehead">
  113.       <td height="25" colspan="3"><span class="tablecontent2"><a href="javascript:onclick=checkAll();" class="size">Select
  114.         all | </a><a href="javascript:onclick=uncheckAll();" class="size">UnSelect
  115.         All</a> | <a href="javascript:onclick=deleted(frmcategory);" class="size">Delete
  116.         SELECTED </a></span>
  117.         <div align="center"></div>
  118.         <div align="center"></div></td>
  119.     </tr>
  120.     <? }else{?>
  121.     <font face="Verdana, Arial, Helvetica, sans-serif" size="+1" color="#FF0000">
  122.     <center>
  123.       <? print "Sorry!No Records Found !!!";?>
  124.     </center>
  125.     </font>
  126.     <? }?>
  127.   </table>
  128.  
  129.   <p class="headerfont">&nbsp;</p>
  130. </form>
  131.  
<? include "includes/pageend.php"; ?>


and this is the function category coding

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?
  3. function CheckCategory($objArray){ 
  4.     $QryCheck="SELECT * 
  5.                 FROM 
  6.                 tbl_categories 
  7.                 WHERE
  8.                 CategoryName ='".$objArray["frmCategoryName"]."' 
  9.                 AND 
  10.                 CategoryId <> '" .$_GET['id']."' 
  11.                 AND IsDeleted='No'";
  12.     $ResCheck = SelectQry($QryCheck);//Calling the Functions_db
  13.     if(is_array($ResCheck))
  14.         return 1;
  15.     else 
  16.         return 0;
  17. }
  18.  
  19. function InsertCategory($objArray){
  20.     $strAddedDate = date("Y-m-d h:m:s");
  21.     $strAddedIP = $_SERVER['REMOTE_ADDR'];
  22.     $QryInsert     =    "INSERT 
  23.                          INTO 
  24.                             tbl_categories(
  25.                             CategoryName,
  26.                             CategoryDescription,
  27.                             AddedDate,
  28.                             AddedIP
  29.                             ) 
  30.                          VALUES 
  31.                             ('".$objArray["frmCategoryName"]."',
  32.                             '".$objArray["frmCategoryDescription"]."',
  33.                             '".$strAddedDate."',
  34.                             '".$strAddedIP."')";
  35.  
  36.     if(ExecuteQry($QryInsert))//calling the functions Execute Query
  37.         return 1;
  38.     else 
  39.         return 0;
  40.  
  41. }
  42. function getCategoryList()    {
  43.     $QryCategory = "SELECT *
  44.                     FROM 
  45.                         tbl_categories
  46.                     ORDER BY
  47.                      CategoryId ";
  48.     $ResultCategory = SelectQry($QyrCategory);
  49.     if(is_array($ResultCategory))    {
  50.         return $ResultCategory;
  51.     }
  52.     else {
  53.         return 0;
  54.     }    
  55. }
  56.  
  57. function CheckUpdateCategory($objArray) {
  58.     $Query = "UPDATE 
  59.                   tbl_categories
  60.                   SET
  61.                        CategoryName = '".$objArray["frmCategoryName"]."',
  62.                        CategoryDescription = '".$objArray["frmCategoryDescription"]."',
  63.                        AddedDate = '".$strAddedDate."'
  64.                   WHERE
  65.                        tbl_categories. CategoryId= '".$_GET['id']."'
  66.                   ";
  67.  
  68.         if(ExecuteQry($Query))
  69.             return 1;
  70.         else
  71.             return 0;
  72.     }
  73. function doDeleteAll($objArray){
  74.  
  75.  
  76.     foreach($objArray['frmcheckall'] as $strkey=>$strValue) {
  77.             $strDeleteId = $strValue;
  78.  
  79.              doDelete($strDeleteId);
  80.               //print_r($strDeleteId);
  81.                         /*$strQuery=  "UPDATE 
  82.                            tbl_categories  
  83.                           SET 
  84.                               IsDeleted = 'Yes' 
  85.                           WHERE
  86.                               Ident =".$strDeleteId." 
  87.                            LIMIT 1";*/
  88.  
  89.                           //doDelete($objGetArray['id']);
  90.  
  91. /*if(doDelete($objGetArray['id'])){
  92.             return 1;
  93.             //print_r(($objGetArray['id']));
  94.             }
  95.             else{
  96.             return 0;}*/
  97.         }
  98.     }
  99.  
  100. /*function doDelete($objGetArray){
  101.     if(is_numeric($objGetArray['id'])){
  102.         $strQuery="SELECT * 
  103.                    FROM
  104.                           tbl_categories 
  105.                    WHERE 
  106.                       Ident=".$objGetArray['id'];
  107.         $strRows = SelectQry($strQuery);
  108.         if(is_array($strRows)){
  109.             $strQuery = "UPDATE
  110.                              tbl_categories 
  111.                          SET 
  112.                               IsDeleted = 'Yes' 
  113.                          WHERE  
  114.                               Ident =".$objGetArray['id']." 
  115.                          LIMIT 1";
  116.             ExecuteQry($strQuery);
  117.             return 1;
  118.         }else{
  119.             return 0;
  120.         }
  121.     }else{
  122.             return 0;
  123.     }
  124. } */
  125. function doDelete($strDeleteId){
  126. //print_r($objGetArray);
  127. //if($objGetArray['id']){
  128. $strQuery = "UPDATE
  129.                          tbl_categories 
  130.                          SET 
  131.                               IsDeleted = 'Yes' 
  132.                          WHERE  
  133.                               CategoryId = '".$strDeleteId."'";
  134.  // print_r($strQuery);
  135.         if(ExecuteQry($strQuery))
  136.             return 1;
  137.         else
  138.             return 0;
  139.  
  140.     }
  141.  
  142. function CheckId($objArray) {
  143. $strAddedDate=date("Y-m-d h:m:s");
  144. $strIp=$_SERVER['REMOTE_ADDR'];
  145.         if(is_numeric($_GET[id])){
  146.                 $Query = "SELECT * 
  147.                           FROM
  148.                                tbl_categories 
  149.                           WHERE  
  150.                                 CategoryId=".$_GET['id'] ;
  151.                 $strRecords = SelectQry($Query );
  152.                 if(!is_array($strRecords)) {
  153.                     return 0;
  154.                 }else{
  155.                     ExecuteQry($Query);
  156.                     return $strRecords;
  157.                 }
  158.             }
  159. }
  160.  
  161. ?>
  162.  
  163.  
Nov 1 '08 #1
21 2785
Markus
6,050 Expert 4TB
First of all, we don't need every file you use. The error should point to a specific file (and also line number) - something which you have neglected to include. Secondly, I don't see a foreach loop anywhere, but that's maybe because my brain hurts from trying to browse all that code you supplied. Thirdly, read the Posting Guidelines pay attention on the part on how to ask a question. You have provided barely any information that could be of use and, therefore, you will be lucky to receive any help.

Please revise your post and then ask your question again.

PS: The error is because you aren't passing an array to a foreach loop.
Nov 1 '08 #2
Markus
6,050 Expert 4TB
Rashgang, is there a reason you are double posting your thread after being told previously not to do so? You are already on thin lines for your disregard to our forum guidelines.

I'm giving you the benefit of the doubt here: this is your final warning before receiving a ban or some sort.
Nov 1 '08 #3
ok here after i will not double posting
Nov 3 '08 #4
nathj
938 Expert 512MB
Hi,

First of al I agree with Markus - a pointer to the line would have been nice. I have, using a ctrl+f tracked down the line.

For those interested it's line 76 the third code listing

I recommend you change the first parameter to $objArray, that should do you.

Cheers
nathj
Nov 3 '08 #5
not helpful plz where to change tell me exactly
Nov 19 '08 #6
nathj
938 Expert 512MB
I'm not sure if something has happened when threads have been merged but the line and code sample I was referring to are no longer present.

I'm also not sure what the problem is, this is the main issue with double posting.

If you could post back with a small relevant code sample indicating the following:

1. what the code should do
2. what the code is not doing that it should do
3. what the code is doing that it should not do
4. any error messages you are getting with line numbers (based on the code snippet)

With that information I'm sure we'll be able to help you out pretty quickly.

Cheers
nathj
Nov 19 '08 #7
nathj
938 Expert 512MB
not helpful plz where to change tell me exactly
line 76 of the third code sample.

currently this read:
Expand|Select|Wrap|Line Numbers
  1. foreach($objArray['frmcheckall'] as $strkey=>$strValue) {
  2.  
Try making it:
Expand|Select|Wrap|Line Numbers
  1. foreach($objArray as $strkey=>$strValue) {
  2.  
Nov 19 '08 #8
i have given the checkbox in dynamic and highlight the row and when i click check all the error is coming tells that warning : foreach invaid argument in line no 75
i cant check the checkboxes
Nov 21 '08 #9
nathj
938 Expert 512MB
Please supply line 75 of your code for us to look at. It's impossible to diagnose a syntax error like this without seeing the syntax you have used.

nathj
Nov 21 '08 #10
Expand|Select|Wrap|Line Numbers
  1. function doDeleteAll(){
  2.     foreach($objArray['frmcheckall'] as $strkey=>$strValue) {
  3.             $strDeleteId = $strValue;
  4.                doDelete($strDeleteId);
Jan 13 '09 #11
Markus
6,050 Expert 4TB
@rashgang
Is $objArray['frmcheckall'] an array? It has to be for foreach to work.
Jan 13 '09 #12
yes frmcheckall is an array. how to take screen shot and send the error page to u
Jan 16 '09 #13
select all and unselect all working but when i click delete selected i got error
Expand|Select|Wrap|Line Numbers
  1. warning: Invalid argument supplied for foreach() in /home/webuser/html/training/arunkarthik/siteadmins/includes/Functions_category.php
on line 77 i am doing like yahoo mail first check all and delete the selected one
Jan 16 '09 #14
code green
1,726 Expert 1GB
Why are you not paying attention to the help given???
Your problem has been answered but you are completeley ignoring the comments
As Markus asked
Is $objArray['frmcheckall'] an array? It has to be for foreach to work
As you completeley ignored him I will answer for you.
No it isn't, because nathj suggestion
line 76 of the third code sample.
currently this read:
Expand|Select|Wrap|Line Numbers
  1. foreach($objArray['frmcheckall'] as $strkey=>$strValue) { 
Try making it:
Expand|Select|Wrap|Line Numbers
  1. foreach($objArray as $strkey=>$strValue) {
Points out the problem
As you have totally ignored them I will repeat

this line calls doDeleteAll() in which the WHOLE $_POST array is passed
Expand|Select|Wrap|Line Numbers
  1.  
  2. if($_POST['frmcheckall']){     
  3.        print doDeleteAll($_POST); 
  4.  
Yet in the function you are trying to loop ONE element only
Expand|Select|Wrap|Line Numbers
  1.  
  2. foreach($objArray['frmcheckall'] as $strkey=>$strValue) 
  3.  
Carry out nathj suggestion then we will look at your checkboxes
Jan 16 '09 #15
Thanks for the help now its solved
Jan 17 '09 #16
only one element is deleted if there two check boxes only one is deleted
Jan 17 '09 #17
if i change it to $objarray as strkey only one element is deleted
Jan 17 '09 #18
code green
1,726 Expert 1GB
Echo out the parameters passed into the doDeleteAll() function
Jan 19 '09 #19
I have echo out the parameters Again one element is deleted
this is the changed function which i have used

function doDeleteAll($objArray){


foreach($objArray as $strkey=>$strValue) {
$strDeleteId = $strValue;

doDelete($strDeleteId); } }
Jan 19 '09 #20
code green
1,726 Expert 1GB
Why do you keep arguing?
You have not inserted a line to echo out the function parameters.
You have not told us the contents of the parameters
Expand|Select|Wrap|Line Numbers
  1.  
  2. function doDeleteAll($objArray){
  3.  print_r($objArray);
  4.  
Jan 19 '09 #21
ok now the problem solved
Jan 19 '09 #22

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

Similar topics

35
by: jerrygarciuh | last post by:
Hi all, I was just wondering what popular opinion is on PHP giving this warning: Warning: Invalid argument supplied for foreach() in /home/boogerpic/public_html/my.php on line 6 when...
4
by: Ryanlawrence1 | last post by:
Heya, I get these 2 errors: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/themepar/public_html/changepass.php on line 20 You have not entered all the...
2
by: techjohnny | last post by:
Error: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/jplane/certcent/phpweb/quiz/index.php on line 20 Warning: mysql_num_rows(): supplied argument is...
1
by: lsmamadele | last post by:
I am getting the following error messages in my search: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mamadele/public_html/BESTPLAYS/search.php on...
11
by: Breana | last post by:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/breana/public_html/category.php on line 88 ------------------------------------------- It does this...
2
by: yogitha | last post by:
For the below code i am getting an error like : --------------------------------------------------------------- Warning: fread(): supplied argument is not a valid stream resource in...
1
by: custom3 | last post by:
Hello, I keep getting the following warning: "PHP Warning: Invalid argument supplied for foreach() in /home/csiexecu/public_html/modules/mod_mainmenu.php on line 339" I am a novice Joomla...
1
by: guoxin | last post by:
Hi All, May i know how to rectify the following php error? Thanks folks Warning: Invalid argument supplied for foreach() in /home/alan/do_add-user.php on line 36 do_add-user.php.php on...
1
by: BryanA | last post by:
Something seems to be wrong with this function and I can't figure out why it is failing. The error that it gives is; Invalid argument supplied for foreach() . function transposition($words){...
14
by: rashgang | last post by:
i have dynamically created checkbox which will like yahoo mail if check box selected it will highlight a row but deleteall function is not working plz chek it function doDeleteAll($objArray){ ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.