473,839 Members | 1,468 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
21 2821
rashgang
17 New Member
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 Recognized Expert Expert
@rashgang
Is $objArray['frmcheckall'] an array? It has to be for foreach to work.
Jan 13 '09 #12
rashgang
17 New Member
yes frmcheckall is an array. how to take screen shot and send the error page to u
Jan 16 '09 #13
rashgang
17 New Member
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 Recognized Expert Top Contributor
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
rashgang
17 New Member
Thanks for the help now its solved
Jan 17 '09 #16
rashgang
17 New Member
only one element is deleted if there two check boxes only one is deleted
Jan 17 '09 #17
rashgang
17 New Member
if i change it to $objarray as strkey only one element is deleted
Jan 17 '09 #18
code green
1,726 Recognized Expert Top Contributor
Echo out the parameters passed into the doDeleteAll() function
Jan 19 '09 #19
rashgang
17 New Member
I have echo out the parameters Again one element is deleted
this is the changed function which i have used

function doDeleteAll($ob jArray){


foreach($objArr ay as $strkey=>$strVa lue) {
$strDeleteId = $strValue;

doDelete($strDe leteId); } }
Jan 19 '09 #20

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

Similar topics

35
3233
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
7841
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
16943
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
2716
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
3612
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
10294
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
1357
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
3358
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
9854
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
9696
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
10584
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...
0
10290
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
9425
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4482
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3131
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.