mysql_num_rows() error


I am not a developer but i have a PHP based system that was developed for me a long time ago. It has been working perfectly fine but all of a sudden i started getting the following errors:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /homepages/6/d141070459/htdocs/AcOrdersMix.php on line 67

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /homepages/6/d141070459/htdocs/OrdersMixListU.php on line 154


I think this must be down to the host ( upgrading thier servers last Thursday.

Can anyone advise what change i need to make? Any help would be greatly appreciated.

Thanks in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan CraciunIT ConsultantCommented:
I think you'll need to ask your host what they upgraded.

For ex, in PHP 5.5 anything starting with mysql_ is deprecated.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
babykdjahAuthor Commented:
i believe that is the issue. i was being charged for using php 5.0 but it appears that is no longer available.

is there an easy way to update the query or is it a case of rewriting it?
Dan CraciunIT ConsultantCommented:
The changes should be fairly small.
mysql_query($sql) becomes mysqli->query(sql) and so on.

See here for an article:

And here for the man page:
Ray PaseurCommented:
Sorry to say, but PHP 5.0 has been obsolete for several years.  So has MySQL.  This is an inflection point in the life of your web site -- maybe a good time to get a professional to help you upgrade to a modern version of the software.  It's not easy nor inexpensive, but it's required every few years and you can get a future-proof system that will keep you out of trouble for a while.  Technology is always advancing!
Ray PaseurCommented:
Here is line 67 of ACOrdersMix (it's the last line in this small snippet).
		$sql = "select O.*,DATE_FORMAT(O.order_date1,'%d/%m/%Y') as orderd_date, IF(O.is_manual='1', O.manual_price, 'NULL') AS amount,DATE_FORMAT(O.verified_date,'%D %M %Y') as invoice_date,U.usertitle AS utitle, U.firstname AS ufirstname, U.middlename AS umiddlename, U.lastname AS ulastname, U.companyname, U.addressline1, U.addressline2, U.addressline3, U.addressline4,, U.county AS state, U.postalcode,R.usertitle AS Rtitle, R.firstname AS Rfirstname, R.middlename AS Rmiddlename, R.lastname AS Rlastname, R.companyname AS Rcompanyname, R.addressline1 AS Raddressline1, R.addressline2 AS Raddressline2, R.addressline3 AS Raddressline3, R.addressline4 AS Raddressline4, AS Rcity, R.county  AS Rstate, R.postalcode AS Rpostalcode from orders_mix O LEFT JOIN tblusers R ON O.reseller_id=R.userid, tblusers U where ".$asql." O.is_ac='1' and (O.is_acp='0' or O.is_acp IS NULL OR O.is_acp = '') AND O.userid=U.userid group by O.orders_id order by O.orders_id desc";
    	$rows = mysql_query($sql);
  $total_results = mysql_num_rows($rows);

Open in new window

This attempts to assign variable $total_results by calling the mysql_num_rows() function with a dependency on the $rows variable.  The line above attempts to assign the $rows variable by calling the mysql_query() function with a dependency on the $sql variable that is set on the line above.  The programming task here is twofold.

First and most importantly, you must find out why the query failed.  To do that, the script should examine the $rows variable, and if it is FALSE, the script should print out the contents of the $sql variable and the contents of the mysql_error() function.  I'm slightly amazed that this script has been running all this time without exactly this failure.  MySQL is not a black box -- it can and will fail for reasons that are outside of your control and a professionally written script would test for that condition and handle the errors.

Second, once you know what caused the query failure, you can set about remediating that condition.

In either case it will require programming knowledge, since you must change the scripts.  This would also be a good time to have a security expert inspect the scripts and advise you about how to "tighten up" the numerous security holes.  There are practices in the programming that we haven't used in a decade, owing to the known risks, so now would be a good time to get that fixed, too.

You can probably keep the underlying database and most of the query strings, but a quick inspection tells me that you may want to completely rewrite the application code.  It looks beyond repair.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.