473,804 Members | 4,288 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Warning: Invalid argument supplied for foreach()

17 New Member
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"include s/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 2819
Markus
6,050 Recognized Expert Expert
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 Recognized Expert Expert
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
rashgang
17 New Member
ok here after i will not double posting
Nov 3 '08 #4
nathj
938 Recognized Expert Contributor
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
rashgang
17 New Member
not helpful plz where to change tell me exactly
Nov 19 '08 #6
nathj
938 Recognized Expert Contributor
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 Recognized Expert Contributor
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
rashgang
17 New Member
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 Recognized Expert Contributor
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

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

Similar topics

35
3229
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 presented with an indefined variable. It makes sense to me to warn if an unacceptably defined var is passed but it
4
7838
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 fields Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/themepar/public_html/changepass.php on line 34 Sorry You failed to enter the correct old password I was wondering if anyone could help me, I have...
2
16938
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 not a valid MySQL result resource in /home/jplane/certcent/phpweb/quiz/index.php on line 21 PHP CODE:
1
2714
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 line 113 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/mamadele/public_html/BESTPLAYS/search.php on line 127 My code is below. Any help would be much appreciated. ...
11
3610
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 when there is no result "empty table" how can i do a quick fix to say No Results... row 88: if ($myrow = mysql_fetch_array($result)) { do { if ($rowcolor == 1) {
2
10293
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 D:\Public_Site\multifileupload\welcome_addfiles.php on line 28 ------------------------------------------------------------ i am trying many ways by giving diff arguments in fread() --------------------------------------------------- suggest me , wat error...
1
1539
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 user that has just upgraded to 1.0.13. Can anyone give me direction on how or to whom I should go to fix this problem? The home page intermittently loads and times out. Thanks!
1
1354
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 line 304: $project_array = $_POST;
1
1643
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){ foreach($words as $word){ for($x=0;$x<strlen($word)-1;$x++){ $results = substr($word, 0, $x) . $word . $word . substr($word, $x+2, strlen($word));
14
3355
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){ foreach($objArray as $strkey=>$strValue) { $strDeleteId = $strValue; doDelete($strDeleteId);
0
9710
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
9589
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
10593
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
10340
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
10329
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
10085
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...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3830
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3000
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.