473,372 Members | 1,173 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,372 software developers and data experts.

How to fix: "Warning: mysql_fetch_assoc(): supplied argument is not a valid . . "?

wilsonh
Hi

I am aware that this is a common problem as I have scoured the internet endlessly looking for a solution.

The script was installed and set up for me because I am a complete beginner so unfortunately I have made little sense of some of the solutions that have been posted.

I have looked into it and now have some understanding of what the code should be doing or what it is trying to do.


The error is

"Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /path/to/file/index.php on line 213"

Line 213 is....

Expand|Select|Wrap|Line Numbers
  1. while($row = mysql_fetch_assoc($rs)) {
  2.  
This is strange because this script originally worked absolutely fine until I tried uploading a new design for the index page (with the original php code re-inserted).
I have even uploaded the original files (but left the db intact) and the error still occurs.

I spoke to a friend of mine and he mentioned something about the variable being returned as false and I need to perform some type of operation on the database maybe.

Do you have any suggestions on what I need to do?

This is the code that connects to the db...

Expand|Select|Wrap|Line Numbers
  1. $conn = mysql_connect($hostname,$username,$password) or die("Having problem connecting to database");
  2.     mysql_select_db($dbname,$conn);
I can also provide the full code by request.

Thanks in advance

Will
Dec 1 '10
10 3078
Dormilich
8,658 Expert Mod 8TB
the problem likely arises in a mysql_query() call. die with an error message there.
Expand|Select|Wrap|Line Numbers
  1. $res = mysql_query($sql) or die("Error in $sql: " . mysql_error());
Dec 2 '10
Thanks for your reply Dormilich but I am still unclear as to what I need to do
Dec 2 '10
Dormilich
8,658 Expert Mod 8TB
try the following. go to line #213 in index.php, look for mysql_query() that is called before that, insert/append the code from post#2, post result here.
Dec 2 '10
There is no mysql_query that I can see.
I added your code just before line 213. This has removed the original error message but it now displays....

"Error in select name,expiration,ext from domains where 1=1: Lost connection to MySQL server during query"

Is there anyway I can show you the whole code of index.php?
There are about 250 lines of code which are too many to post here.
Dec 2 '10
Dormilich
8,658 Expert Mod 8TB
you can put it in a zip file and attach it. post the zip file’s checksum too (sha1 preferred)
Dec 2 '10
Thanks Dormilich, I have attached the files as requested.
There are 2 other files included in the zip (files linked to the index which may be of some help).
Attached Files
File Type: zip wilsonh.zip (5.8 KB, 94 views)
File Type: txt checksum.txt (40 Bytes, 289 views)
Dec 2 '10
Dormilich
8,658 Expert Mod 8TB
the problem here is improper class design.

the method PS_Pagination->paginate() (ps_pagination.php:60) does not return a consistent result. if the query succeeds, it returns a resource, if the query fails (what is happening here) it returns false (just like mysql_query()). therefore as immediate fix you have to check the $rs variable (index.php:191) before using it (index.php:213).

if you’re running PHP 5, I recommend a different pagination class (this code is for PHP 4). in PHP 5 there are enough mechanisms available to avoid those problems, but coding all those in the current code would be a waste of effort. IMO, this class’ code needs a complete rewrite.
Dec 2 '10
Thanks for having a look, I really appreciate it!

Can you tell me how I would check the $rs variable?

Also, for a re-write is this a big job that I would need to pay somebody to do or could I find the code online?

Sorry to keep asking questions, I am a complete beginner with php and mysql
Dec 2 '10
Dormilich
8,658 Expert Mod 8TB
check the variable:
Expand|Select|Wrap|Line Numbers
  1. // PHP 5
  2. if (!$rs) 
  3. {
  4.     throw new RuntimeException("The Query failed.");
  5. }
this requires your code wrapped in a try … catch block. (cf. Exceptions)

rewrite, first you should search the net for other pagination classes. chances are that you’ll find something suitable. esp. pay attention to error handling.

the only thing I could offer you is a solid database handling system for PHP 5 …
Dec 2 '10
Ok thanks for that!
I'll have a scour around and see if I can find anything!
Dec 2 '10

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

Similar topics

6
by: aa | last post by:
I use the following fragment of code to output datf from MySQL: ====================================================== $chan = mysql_connect ($db_host, $username, $password); mysql_select_db...
4
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...
2
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...
11
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...
6
by: Tinker | last post by:
hi i am having a problem i can figure out can some one please tell me how to fix this PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /hermes/ i took out the...
4
by: simon2x1 | last post by:
how can i fix these error and what does it mean Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\test_php\log\search\result.php on line 8 ...
2
by: perhapscwk | last post by:
When I run my site from localhost, no error, but when I move it to webhosting, it show below error, why? Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in...
0
Atli
by: Atli | last post by:
What to discuss: What is a "MySQL resource". What causes the error. How to fix it. Common Newbie Pitfalls This article is the second installment in a series of (hopefully) many, following...
1
by: kmacc | last post by:
Hi, I'm getting this error on a page after changing server host, the error did not happen on my old host. I'm thinking it is to do with a new MySQL version and more strict coding. Can anyone help?...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.