473,769 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Warning: mysql_fetch_ass oc(): supplied argument is not a valid MySQL result resource

38 New Member
I am connecting to my database using Object oriented PHP. My query is returning results but at the end of my table,at the bottom of the page I keep having this error when I run my program: Warning: mysql_fetch_ass oc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs \mysql_class_2. php on line 45.

Can anyone help me?

The following is my PHP class:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. class mysql {
  3. ////////////////////////////////////////////////////////////////
  4. function Connect($host, $name, $pass, $db){
  5. $connection = mysql_connect("$host","$name","$pass");
  6. mysql_select_db("$db", $connection);
  7. }//ends the connection function
  8. ///////////////////////////////////////////////////////////////
  9. function Close(){
  10. mysql_close($this->connection);
  11. }//ends the close function
  12. //////////////////////////////////////////////////////////////
  13. function FetchRow($query){
  14. $rows = mysql_fetch_row($query);
  15. return $rows;
  16. }
  17. ////////////////////////////////////////////////////////////
  18. function FetchArray($query){
  19. $array = mysql_fetch_array($query);
  20. return $array;
  21. }
  22. ///////////////////////////////////////////////////////////
  23. function FetchNum($query){
  24. while ($num = mysql_num_rows($query));
  25. return $num;
  26. }
  27. ////////////////////////////////////////////////////////////////
  28. function Query($sql){
  29. $query = mysql_query($sql) or die(mysql_error());
  30. return $query;
  31. }//ends the query function
  32. ///////////////////////////////////////////////////////////////////////////////
  33. function FetchAssoc($query2){
  34. $array = mysql_fetch_assoc($query2);
  35. return $array;
  36. }
  37. ///////////////////////////////////////////////////////////////////////////////
  38. function TanimotoSimilarity($query,$input_arrays) {
  39. $i=0;
  40. $row= array();
  41. while( $row=mysql_fetch_assoc($query) )
  42. {
  43. $first[$i]=(count(array_intersect($row,$input_arrays)))/(count($row)+count($input_arrays)-count(array_intersect($row,$input_arrays)));
  44. $i++;
  45. }
  46. return($first);
  47.  
  48. }
  49. ///////////////////////////////////////////////////////////////////////////////////
  50. }//ends the class
  51. ?>
  52.  
On the code above Mysql_fetch_ass on function is on line 33.

Thanks
Jan 8 '09 #1
2 16983
Atli
5,058 Recognized Expert Expert
Hi.

You get that warning when you try to fetch rows from a variable that is not a MySQL query resource.
(A MySQL query resource is the return value of a successful mysql_query call)

To avoid it, you need to make sure that the parameter you are passing it is in fact a valid resource. This usually works fine:
Expand|Select|Wrap|Line Numbers
  1. if($resource and !is_bool($resource)) {
  2.   $row = mysql_fetch_assoc($resource);
  3. }
When a mysql_query call fails, it returns FALSE, or in the case of successful queries that do not return a result set, TRUE.

P.S.
What's with the while loop on line 24?
Jan 8 '09 #2
poreko
38 New Member
The while loop in line 24 is my mistake. It was just me trying something out.
Jan 8 '09 #3

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

Similar topics

3
3919
by: petemaxi | last post by:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\tockholes\includes\menu.inc.php on line 9 <div class="left"> <div class="menu"> <div class="boxhead" style="text-align:center;"> <strong>Menu</strong> </div> <br /> <?php require ('includes/db_conn.inc.php'); $query = "select * from menu order by item_order"; $result = mysql_query($query);
11
3608
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) {
3
1260
by: chri | last post by:
hi i get the following errors returning me folloing post to data base Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\chris1\My Documents\xampp\htdocs\elp\modify_information.php on line 89 Warning: Cannot modify header information - headers already sent by (output started at C:\Documents and Settings\chris1\My Documents\xampp\htdocs\elp\modify_information.php:89) in...
5
2357
by: Mubs | last post by:
Hi, I 'am trying to connect my sql database with my webpage for users log in. i have got this script so far but i keep getting the following error message which i cannot figure out.. could any1 help.. error:Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\checklogin.php on line 18 Wrong Username or Password code:
4
5030
by: fisherd | last post by:
When i run this code, i keep getting this message; Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\checklogin.php on line 26 i use this code to check login details. Here is the code for the pages that i used. main_login.php <html> <body>
4
2301
by: kalyanip14 | last post by:
Hi I am new to Php.I am trying to read My sql database data from table to php. I am getting this warning Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource and my code is <?php
1
3407
mideastgirl
by: mideastgirl | last post by:
What does this error mean? Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/m/i/d/mideasthonors/html/student_session_proposal_success.php on line 109 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 This is the code, but I am not seeing what they are talking about: <?...
2
3230
by: macdalor | last post by:
Hi! I'm completely new to all dev and trying to put a website together using MySQLI and PHP; was running fine until I try to gather the DB content with the following script: <? $username="xxxxxx"; $password="xxxxxx"; $database="maxalien_davidloran"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM contacts";
9
4531
by: Cxsey | last post by:
I get the following error code using this code: "Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource" It's on line 55 in this php script: <?php /** * Database.php * * The Database class is meant to simplify the task of accessing
0
9589
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
9865
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
8873
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...
1
7413
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
6675
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();...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
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
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.