473,395 Members | 2,006 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,395 software developers and data experts.

can help me spot the error?

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

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

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/emcasia/public_html/pepadmin/create_report.php 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 2245
Markus
6,050 Expert 4TB
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
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...
1
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
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....
3
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......
8
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))...
42
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...
5
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...
2
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)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
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
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,...
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
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...
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,...

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.