MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 21st, 2004, 01:35 AM
asiansINC.com asiansINC.com is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 3 asiansINC.com User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
mysql_num_rows() and mysql_fetch_array() errors

I've googled this site extensively, but can't figure out what's wrong with the script that I'm trying to run.

Here's the code:

PHP Code:
<?
session_start
();
session_destroy();
$who=$_GET['from'];
$ref=$_SERVER['HTTP_REFERER'];
unset(
$HTTP_SESSION_VARS["sponsor"]);
unset(
$HTTP_SESSION_VARS["random"]);
setcookie("sponsor_is"""time()-3600);
setcookie("sponsor_is"$whotime()+24*60*60*365);
require_once(
"db_connect.php");
$s=mysql_query("SELECT * FROM users WHERE username='.mysql_real_escape_string(strtolower($wh  o)).' and status=1");
//if no valid sponsor entered, let's just pay the admin
if(mysql_num_rows($s)<1){
 
$s=mysql_query("SELECT * FROM users WHERE id=1");
 }
@
session_register("sponsor");
$HTTP_SESSION_VARS["sponsor"]=mysql_fetch_array($s);
$r=mysql_query("INSERT INTO 'hits' ('username' , 'refer' , 'ip' , 'date' )
VALUES ( '"
.$who."', '$ref', '$REMOTE_ADDR',now())");
echo 
"<meta http-equiv='Refresh' content='0; url=index.php'>";
?>


This is the error that I get:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home2/random/public_html/promo.php on line 13

So I tried commenting out lines 13-15 if(mysql_num_rows($s)<1){$s=mysql_query("SELECT * FROM users WHERE id=1");}

But then running the script gave me this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/random/public_html/promo.php on line 17

I've tried adding or die in various places, but no errors showed up.

Any help is greatly appreciated.

Reply With Quote
  #2  
Old July 21st, 2004, 07:36 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
The call to mysql_fetch_array() is failing because you commented out the mysql_query(), which fails because you don't have a valid connection to the database. Paste in your db_connect.php (change username and password values) and let's have a look at that.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #3  
Old July 21st, 2004, 08:26 PM
asiansINC.com asiansINC.com is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 3 asiansINC.com User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This is db_connect.php:

PHP Code:
<? 
/*This is the mysql connection parameters.
For maximum security,you can move this file outside the 
web tree .
In this case,please edit the path from the line 100 of config.php.*/
$dbhost 'localhost';
$database_name 'database_name';
$dbusername 'database_username';
$dbpasswd 'database_password';
$connection mysql_pconnect("$dbhost","$dbusername","$dbpasswd"
 or die (
"Couldn't connect to server.");
 
$db mysql_select_db("$database_name"$connection)
 or die(
"Couldn't select database.");
 
?>

Reply With Quote
  #4  
Old July 22nd, 2004, 08:36 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Try prepending "@" to all of your mysql functions. The errors you're getting are warnings and so this may just be a matter of your log level being set too high. Sticking "@" at the beginning of the functions should suppress the errors, while having die statements will print out any real problems. I'd recommend adding the output of mysql_error() to your die statements during development.

Reply With Quote
  #5  
Old July 25th, 2004, 01:17 AM
asiansINC.com asiansINC.com is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 3 asiansINC.com User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you, dhouston.

Can you give me an example of where I should be prepending "@"?

Reply With Quote
  #6  
Old July 26th, 2004, 07:54 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Code:
$connection = @mysql_pconnect("$dbhost","$dbusername","$dbpasswd") or die ("Couldn't connect to server.");

Reply With Quote
  #7  
Old July 29th, 2004, 07:33 PM
tim_ver tim_ver is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 7 tim_ver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Error ?

I get some what of the same error mesg.


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/main/public_html/Job8/meta.inc on line 7


Is this the same?

Thanks

Reply With Quote
  #8  
Old July 29th, 2004, 10:07 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Add the @ sign to that function as well, and to any others that generate the error.

Reply With Quote
  #9  
Old July 29th, 2004, 10:47 PM
tim_ver tim_ver is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 7 tim_ver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Changed it..

Ok for this line 7 is:

$meta_row = mysql_fetch_array($meta_return);

I changed it to: @meta_row = mysql_fetch_array($meta_return);


I get a parse error.

I tried

$meta_row = @mysql_fetch_array($meta_return);

And it went away. Is this ok or just a band aid?

Thanks

Reply With Quote
  #10  
Old July 30th, 2004, 08:16 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
See response at http://forums.devarticles.com/t9344/s.html. In short, it's somewhere between a band-aid and a fix.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > mysql_num_rows() and mysql_fetch_array() errors


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT