hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : C'mon man... mysql_fetch_array!!!
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

C'mon man... mysql_fetch_array!!!

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 10-10-2005, 02:44 PM
seodevhead seodevhead is offline
Web Hosting Evangelist
 
Join Date: Aug 2005
Location: EIB Network
Posts: 474
*

C'mon man... mysql_fetch_array!!!


I am getting this error when trying to count number of records in table 'users':

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

with this code:

PHP Code:
$query "SELECT COUNT(*) FROM users";
    
$result mysql_query($query);
    
$row mysql_fetch_array ($resultMYSQL_NUM);
    
$num_users $row[0];
    echo 
"There are currently " $num_users " registered!"
What the hell is causing the error??? My code looks spot on!??! Any help???

Reply With Quote


Sponsored Links
  #2  
Old 10-10-2005, 03:03 PM
seodevhead seodevhead is offline
Web Hosting Evangelist
 
Join Date: Aug 2005
Location: EIB Network
Posts: 474
HAHA... nevermind...

I forgot I had a msyql_close(); above it. Sorry

Reply With Quote
  #3  
Old 10-11-2005, 03:08 AM
Burhan Burhan is offline
Community Guide
 
Join Date: Jul 2003
Location: Kuwait
Posts: 5,100
Always use mysql_error():
PHP Code:
$query "SELECT COUNT(*) as `num_rows` FROM users";
$result mysql_query($query);
if (!
$result)
{
   die(
$query."<br />".mysql_error());
}
echo 
"Number of users is ".mysql_result($result,0); 

__________________
In order to understand recursion, one must first understand recursion.
If you feel like it, you can read my blog
Signal > Noise

Reply With Quote
Sponsored Links
  #4  
Old 10-11-2005, 07:40 AM
ochiba ochiba is offline
Aspiring Evangelist
 
Join Date: Jan 2002
Posts: 364
Quote:
Originally posted by fyrestrtr
Always use mysql_error():
...in dev only, right?

In production, might not that cause a security issue? By sending bad vars which will purposely cause an error, script-monsters can find out more information about your DB structure and have a better chance of figuring out what they can break.

I dunno, just my opinion ^_^;; but then again, I'm paranoid.

__________________
Best Hosting Experiences: Voxtreme.Com (Shared Reseller / 5yrs), Serverpoint.Com (Dedicated & VPS / 4 yrs)

Reply With Quote
  #5  
Old 10-11-2005, 12:01 PM
jimlundeen jimlundeen is offline
Junior Guru Wannabe
 
Join Date: Sep 2005
Location: Cleveland, Ohio
Posts: 51
There is a happy medium, which is to look at the response from the mysql server, and if it's an error, then gracefully generate your own error message which contains no "helpful" information that bad people might use against you.

__________________
Jim Lundeen
Edgar Technologies

Professional Small Business IT Management
http://edgar-tech.com

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Web Host webHOSTING.net Improves Data Backup Using Nimble Storage Array Web Hosting News 2012-03-28 13:14:22
Web Host Rackspace Launches Private Beta for MySQL Cloud Database Web Hosting News 2011-12-01 21:09:51
Parallels Now Offering Licenses for CloudLinux OS Web Hosting News 2011-10-26 17:29:25
Web Hosting Software Firm CloudLinux Releases CloudLinux OS Version 6.1 Web Hosting News 2011-09-13 14:08:49
Web Host FireHost Partners with Cloud Security Firm Gazzang for Data Encryption Web Hosting News 2011-08-16 20:33:43


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?