473,657 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can help me spot the error?

1 New Member
Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in /home/emcasia/public_html/pepadmin/create_report.p hp on line 202

Warning: mysql_num_field s(): supplied argument is not a valid MySQL result resource in /home/emcasia/public_html/pepadmin/create_report.p hp on line 295

Warning: mysql_fetch_arr ay(): supplied argument is not a valid MySQL result resource in /home/emcasia/public_html/pepadmin/create_report.p hp on line 297

here is the code
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_cache_limiter('private,must-revalidate');    
  3. session_start();
  4.  
  5. require_once("config.php");
  6.  
  7. include ("classes/db_functions.php");
  8. include ("classes/display.php");
  9.  
  10. $dbf=new db_functions(SM_DB_HOST,SM_DB_USER,SM_DB_PASS,SM_DB_NAME);
  11.  
  12. ?>
  13. <link href="style/report.css" rel="stylesheet" type="text/css" />
  14. <?php
  15.  
  16. if (@$_POST['Submit']=="Save Report")
  17. {
  18.  $sql = "select * from customreport order by id desc";
  19.  $linkID=mysql_connect(SM_DB_HOST,SM_DB_USER,SM_DB_PASS);
  20.  mysql_select_db(SM_DB_NAME, $linkID);   
  21.  $result = mysql_query($sql)or die(mysql_error()); 
  22.  $nume = mysql_num_rows($result);
  23.  $row=mysql_fetch_array($result);
  24.  
  25.  if (!empty($nume))
  26.     $nume = $row['id'] + 1; 
  27.  else
  28.     $nume=1;
  29.  
  30.  $reportname = $_POST['reportname'];
  31.  $whereclause = addslashes($_POST['whereclause']);
  32.  $choose = addslashes($_POST['choose']);
  33.  $tablename = $_POST['tablename'];
  34.  if (isset($_SESSION['USERID']) and isset($_SESSION['groupid']))
  35.  {   
  36.     $userid = $_SESSION['USERID'];
  37.     $groupid = $_SESSION['groupid'];
  38.  }   
  39.  else
  40.  {   
  41.     $userid = "NAN";
  42.     $groupid = "NAN";
  43.  }   
  44.  
  45.  
  46.  $viewtype = $_POST['viewtype'];
  47.  
  48.  $sql = "INSERT INTO customreport (id,userid,reportname,whereclause,choose,tablename,viewtype,groupid)".
  49.          " VALUES ('$nume','$userid','$reportname','$whereclause','$choose','$tablename','$viewtype','$groupid')";
  50.  
  51. //echo $sql;
  52. $result= mysql_query($sql); 
  53.  
  54. echo "<center>Report Saved !!</center>";    
  55. exit;    
  56. }
  57.  
  58. $geo = isset($_POST['geo']) ? $_POST['geo'] : "";
  59. $country = isset($_POST['country']) ? $_POST['country'] : "";
  60. $cat = isset($_POST['cat']) ? $_POST['cat'] : "";
  61. $typeofreport = isset($_POST['typeofreport']) ? $_POST['typeofreport'] : "";
  62. $select2= isset($_POST['select2']) ? $_POST['select2'] : "";
  63. $CAM = isset($_POST['CAM']) ? $_POST['CAM'] : "";
  64. $start = isset($_GET['start']) ? $_GET['start'] : "";
  65. $where = isset($_GET['where']) ? $_GET['where'] : "";
  66.  
  67. if (!empty($select2))
  68. {
  69.  
  70. for ( $i = 0 ; $i < count($select2) ; $i++ )
  71. {
  72.  
  73. if ($i==0)
  74. $choose = "`".$select2[$i]."`";
  75. else
  76. $choose = $choose . "," ."`".$select2[$i]."`";
  77. }
  78.   $_SESSION['choose'] = $choose;
  79. }
  80. else
  81. {
  82.     $choose = $_SESSION['choose'];
  83.     $select2 =  explode(",",$_SESSION['choose']);
  84. }
  85.  
  86. if (empty($where))
  87. {
  88. $whereclause = "";
  89.  
  90. if ($typeofreport=="tec")
  91.     if ($cat=="1")
  92.     {
  93.         $sCountry = "`venue_asn.Country`";
  94.         $sGEO = "`venue_asn.GEO`";
  95.     }
  96.     else
  97.     {
  98.         $sCountry = "`venue_pep.Country`";
  99.         $sGEO = "`venue_pep.GEO`";
  100.     }
  101. elseif ($typeofreport=="ec")
  102.     {
  103.         $sCountry = "`company.Country`";
  104.         $sGEO = "`company.GEO`";
  105.     }
  106. elseif ($typeofreport=="pc")
  107.     {
  108.         $sCountry = "`company.Country`";
  109.         $sGEO = "`company.GEO`";
  110.         $sCAM = "`company.CAM`";
  111.     }
  112. elseif ($typeofreport=="pu")
  113.     {
  114.         $sCountry = "Country";
  115.     }
  116. elseif ($typeofreport=="ac")
  117.     {
  118.         $sCountry = "Country";
  119.         $sGEO = "geo";
  120.     }
  121. else
  122.     {
  123.     //    echo "stop";
  124.     //    exit;
  125.     }
  126.  
  127. if (!empty($geo))
  128.     $whereclause = " where $sGEO ='$geo'";
  129.  
  130. if (!empty($country))
  131.     if(!empty($whereclause))
  132.            $whereclause = $whereclause." and $sCountry='$country'";
  133.     else
  134.     $whereclause = " where $sCountry='$country'";
  135.  
  136.  
  137. //if (!empty($date1) && !empty($date2))
  138.  //       if(!empty($whereclause))
  139. //              $whereclause = $whereclause." and (StartDate >= '$date1' and StartDate <= '$date2')";
  140.   //      else
  141.    //             $whereclause = " where (StartDate >= '$date1' and StartDate <= '$date2')";
  142.  
  143.  
  144. if (!empty($CAM) && !empty($CAM))
  145.         if(!empty($whereclause))
  146.                 $whereclause = $whereclause." and $sCAM ='$CAM'";
  147.         else
  148.                 $whereclause = " where $sCAM ='$CAM'";        
  149.  
  150. }
  151.  
  152. else
  153.           {
  154.           $whereclause = stripslashes($_GET['where']);
  155.           }
  156.  
  157. if (empty($typeofreport))
  158.     $typeofreport = isset($_GET['typeofreport']) ? $_GET['typeofreport'] : "";
  159.  
  160. if (empty($cat))
  161.     $cat = isset($_GET['cat']) ? $_GET['cat'] : ""; 
  162.  
  163. if ($typeofreport=="tec")
  164.     if ($cat=="1")
  165.         $tablename = "vwtrainingandeventcats_asn";
  166.     else
  167.         $tablename = "vwtrainingandeventcats_pep";
  168. elseif ($typeofreport=="ec")
  169.     $tablename = "vwelearningcat";
  170. elseif ($typeofreport=="pc")
  171.     $tablename = "vwpartnerscat";
  172. elseif ($typeofreport=="pu")
  173.     $tablename = "pep_user";
  174. elseif ($typeofreport=="ac")
  175.     $tablename = "vwaccreditation";
  176.  
  177.  
  178. $where = urlencode($whereclause);
  179.  
  180. $sql = "select ".$choose." from ".$tablename.$whereclause." Group by ".$choose;
  181.  
  182. //echo $sql;
  183.  
  184. $page_name="create_report.php"; //  If you use this code with a different page ( or file ) name then change this 
  185.  
  186. if(strlen($start) > 0 and !is_numeric($start)){
  187.     echo "Data Error";
  188.     exit;
  189. }
  190.  
  191. $eu = ($start - 0); 
  192. $limit = 10;                                 // No of records to be shown per page.
  193. $this1 = $eu + $limit; 
  194. $back = $eu - $limit; 
  195. $next = $eu + $limit;     
  196.  
  197. $linkID=mysql_connect(SM_DB_HOST,SM_DB_USER,SM_DB_PASS);
  198. mysql_select_db(SM_DB_NAME, $linkID);  
  199. //$result2=mysql_query($sql)or die('Error, query failed');
  200.  
  201. $query = mysql_query($sql);       
  202. $nume = mysql_num_rows($query);  --> line 202
  203.  
  204.  echo $nume;
  205. ?>
  206. <script language="javascript">
  207.  
  208. function checkData()
  209. {
  210.     var a = document.savereport.reportname.value;
  211.     if (a=="")    
  212.     {    
  213.         alert("Please enter the report name !!");    
  214.         return false;
  215.     }
  216. }
  217.  
  218. </script>
  219.  
  220. <?php
  221.     echo "<form action=\"create_report.php\" name=\"savereport\" method=\"post\" onSubmit=\"return checkData();\">";
  222.     echo "Report Name : <input type=\"text\" name=\"reportname\">";
  223.     echo "<input type=\"hidden\" name=\"whereclause\" value=\"$whereclause\">";
  224.     echo "<input type=\"hidden\" name=\"choose\" value=\"$choose\">";
  225.     echo "<input type=\"hidden\" name=\"tablename\" value=\"$tablename\">";
  226.     echo "<input type=\"Submit\" name=\"Submit\" value=\"Save Report\"><br>";
  227.     echo "<input type=\"radio\" name=\"viewtype\" value=\"Public\" checked>Public";
  228.     echo "<input type=\"radio\" name=\"viewtype\" value=\"Private\">Private";
  229.     echo "</form>";
  230.  
  231. //paging start
  232. $p_limit=100; // This should be more than $limit and set to a value for whick links to be breaked
  233.  
  234. @$p_f=$_GET['p_f'];                                // To take care global variable if OFF
  235. if(!($p_f > 0)) {                         // This variable is set to zero for the first page
  236. $p_f = 0;
  237. }
  238.  
  239. $p_fwd=$p_f+$p_limit;
  240. $p_back=$p_f-$p_limit;
  241. //////////// End of variables for advance paging ///////////////
  242. /////////////// Start the buttom links with Prev and next link with page numbers /////////////////
  243. echo "<table align = 'center' width='70%'><tr><td  align='left' width='20%'>";
  244. if($p_f<>0){print "<a href='$page_name?start=$p_back&p_f=$p_back&cat=$cat&where=$where&typeofreport=$typeofreport'><font face='Verdana' size='2'>PREV $p_limit</font></a>"; }
  245. echo "</td><td  align='left' width='10%'>";
  246. //// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
  247. if($back >=0 and ($back >=$p_f)) { 
  248. print "<a href='$page_name?start=$back&p_f=$p_f&cat=$cat&where=$where&typeofreport=$typeofreport'><font face='Verdana' size='2'>PREV</font></a>"; 
  249. //////////////// Let us display the page links at  center. We will not display the current page as a link ///////////
  250. echo "</td><td align=center width='50%'>";
  251. for($i=$p_f;$i < $nume and $i<($p_f+$p_limit);$i=$i+$limit){
  252. $number = $i/10+1;
  253. if($i <> $eu){
  254. $i2=$i+$p_f;
  255. echo " <a href='$page_name?start=$i&p_f=$p_f&cat=$cat&where=$where&typeofreport=$typeofreport'><font face='Verdana' size='2'>$number</font></a> ";
  256. }
  257. else { echo "<font face='Verdana' size='2' color=red>$number</font>";}        /// Current page is not displayed as link and given font color red
  258.  
  259. }
  260.  
  261. echo "</td><td  align='right' width='10%'>";
  262. ///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
  263. if($this1 < $nume and $this1 <($p_f+$p_limit)) { 
  264. print "<a href='$page_name?start=$next&p_f=$p_f&cat=$cat&where=$where&typeofreport=$typeofreport'><font face='Verdana' size='2'>NEXT</font></a>";} 
  265. echo "</td><td  align='right' width='20%'>";
  266. if($p_fwd < $nume){
  267. print "<a href='$page_name?start=$p_fwd&p_f=$p_fwd&cat=$cat&where=$where&typeofreport=$typeofreport'><font face='Verdana' size='2'>NEXT $p_limit</font></a>"; 
  268. }
  269. echo "</td></tr></table>";
  270.  
  271. echo "</td></tr></table>";
  272.       echo "<form action='export_report.php' method='post' target='_blank'>";
  273.       echo "<INPUT type=\"hidden\" name=\"report_type\" value=\"customized_report\">";
  274.       echo "<INPUT type=\"submit\" value=\"Export To Excel\">";
  275.       echo "</form>";
  276.  
  277. //paging end
  278. // echo $tablename.$whereclause.$choose;
  279. // $groupby = " group by ".$choose;
  280. $report = new display($dbf,"vwelearningreport","Company","Company","0");
  281. $report->showreport2($dbf,$tablename,$select2,$whereclause." Group by ".$choose." limit $eu, $limit",$choose);
  282.  
  283. $out = "";
  284.  
  285.      for($i = 0; $i < count($select2); $i++)    
  286.      {
  287.         $out .= $select2[$i]."\t";
  288.      } 
  289.  
  290.      $out .= "\n";
  291.  
  292.     $mymysql="SELECT ".$choose." FROM ".$tablename." ".$whereclause." Group by ".$choose;
  293.     $myresult=mysql_query($mymysql);
  294.     $fieldcount = mysql_num_fields($myresult);  --> line 295
  295.  
  296.     while($myrow=mysql_fetch_array($myresult)) --> line 297
  297.     {
  298.         for($k=0;$k<$fieldcount;$k++)
  299.         {
  300.             $out .= $myrow[$k]."\t";
  301.  
  302.         }
  303.         $out .= ""."\n";
  304.  
  305.     }
  306.      //echo $out;
  307.      $_SESSION["out_customized_report"] = $out;
  308.  
  309. ?>
Jan 8 '10 #1
1 2268
Markus
6,050 Recognized Expert Expert
Welcome to Bytes.com.

The error you are receiving is due to your calls to mysql_query() failing. You do not know this is happening because they fail silently. That is, you have to explicitly check the return value of mysql_query(). If your query fails, the function will return false. Of course, that means your variables will not point to a MySQL result resource and, thus, will fail anywhere you attempt to use them. That said, here is some example code:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. /** This SQL will fail because of a syntax error */
  4. $sql = "SELECT * FRO `tbl_name` WHERE 1";
  5. $res = mysql_query($sql);
  6.  
  7. /** Here we have no idea whether our query ran successfully.
  8.     We can check the return value of the function to see if we should carry on */
  9. if ($res === false) {
  10.     /** We know the query failed. To find out _why_ the query failed, we can use the
  11.         mysql_error() function, which is populated with the latest error */
  12.     printf("Query failed. Error string: <em>%s</em>", 
  13.             mysql_error());
  14.     /** Exit with error */
  15.     exit(1);
  16. }
  17. /** Query ran fine :) */
  18. do_something_with($res);
  19.  
Jan 8 '10 #2

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

Similar topics

3
1305
by: JKop | last post by:
I have some code which when compiled on my system prints: <output> AnyClass Constructor for: blah AnyClass Copy Constructor for: Copy of blah AnyClass Copy Constructor for: Copy of Copy of blah
1
426
by: antipode | last post by:
That's about it. If I make a cursor of any size and color depth, the button to set the hot spot stays disabled. I'm at my wit's end, and yet I know it's got to be something stupid I'm missing.
0
2300
by: gregory_may | last post by:
I apologize for cross posting, but I don't know the best place to post this. This link is a pretty good overview of the various System Cursor routines. http://www.rocklyte.com/pandora/manual/modules/screen.html I am trying to capture the system cursor & superimpose it on a screen shot bit map. The problem I am encountering is custom cursors. Custom cursors have hot spots that are often "off". SetCustomCursor() lets you define the...
3
1226
by: DFS | last post by:
This one had me stymied for a minute. Clicking the button it was attached to seemingly did nothing. ============================= On Error GoTo exitGetData ....code that threw an error... exitGetData:
8
1129
by: Steven Spencer \(Spinalogic\) | last post by:
Dim dlg As New dlgChangeDate Dim fromdate As DateTime = dlg.GetaDate(System.DateTime.Now, "Please Enter the Start of the Holiday") If (Not fromdate.CompareTo(New DateTime(1, 1, 1, 1, 1, 1, 1)) = 0) Then While IsDateBetweenShifts(fromdate, cboHolidayDoctors.SelectedValue) MsgBox("The date you have entered does not occur between the
42
1815
by: NwsGrp1 | last post by:
A colleague is reading through some C articles and was asked if there are any errors in the following code. Neither of us can spot any issues, I have compiled it with VC8 and GCC at their strictest settings and got nothing of note. Here is the code: #include <stdio.h> void usage(char *ptCommand);
5
2557
by: weidongtom | last post by:
Hi, I tried to implement the Universal Machine as described in http://www.boundvariable.org/task.shtml, and I managed to get one implemented (After looking at what other's have done.) But when I use to run a UM program, I kept on getting error messages. I have used someone else's implementation and it runs fine. I have compared my code with other's and I still can't figure it out what's wrong with mine. So please help me out, after 3...
2
2186
by: eloi-ribeiro.blogspot.com | last post by:
Hi, I'm having a problem with a query. I'm running Access 2000 and a table with 35000 rows. The table contains several visits to the spots with a CODE (spot code) and DATE (visit date) columns. Each spot have 10 visits or more, so the CODE is repeated in the column, an the respective DATE of that visit, witch are not repeated. I would like to know the last five visits to each spot. If it's possible.
0
8411
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
8323
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
8838
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
8739
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
8613
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...
1
6176
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2740
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
1732
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.