Urgent error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL re

Reply

Join Date: Oct 2008
Posts: 3
Reputation: gmaster1440 is an unknown quantity at this point 
Solved Threads: 0
gmaster1440 gmaster1440 is offline Offline
Newbie Poster

Urgent error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL re

 
0
  #1
Oct 27th, 2008
Code:

  1. <?php
  2.  
  3. define( "DATABASE_SERVER", "blah" );
  4.  
  5. define( "DATABASE_USERNAME", "blah" );
  6.  
  7. define( "DATABASE_PASSWORD", "blah" );
  8.  
  9. define( "DATABASE_NAME", "blah" );
  10.  
  11. //connect to the database
  12.  
  13. $mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error());
  14.  
  15. mysql_select_db( DATABASE_NAME );
  16.  
  17. $sql = 'SELECT * FROM `users`';
  18. $result = mysql_query($sql) or die ('Error: '.mysql_error ());
  19.  
  20. while($row = mysql_fetch_array($result))
  21. {
  22.  
  23. $hPassword = hash ( sha256, $row['password']);
  24. $query = "INSERT INTO new_users (username, password)
  25. VALUES('".$row['username']."','$hPassword')";
  26.  
  27. $result = mysql_query($query);
  28. }
  29.  
  30. ?>


I keep getting this error:
  1. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/g/m/a/gmaster1440/html/vote/convertdb.php on line 20

Yes, credentials are correct, yes 'users' table exists.

Please guys, this is due for a big project tomorrow. I'll appreciate any help I can get.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Urgent error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL re

 
0
  #2
Oct 27th, 2008
try:

  1. <?php
  2.  
  3. define( "DATABASE_SERVER", "blah" );
  4.  
  5. define( "DATABASE_USERNAME", "blah" );
  6.  
  7. define( "DATABASE_PASSWORD", "blah" );
  8.  
  9. define( "DATABASE_NAME", "blah" );
  10.  
  11. //connect to the database
  12.  
  13. $con = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error());
  14.  
  15. mysql_select_db( DATABASE_NAME );
  16.  
  17. $sql = 'SELECT * FROM `users`';
  18. $result = mysql_query($sql,$con) or die ('Error: '.mysql_error());
  19.  
  20. while($row = mysql_fetch_array($result,MYSQL_ASSOC))
  21. {
  22.  
  23. $hPassword = hash ( sha256, $row['password']);
  24. $query = "INSERT INTO new_users (username, password)
  25. VALUES('".$row['username']."','$hPassword')";
  26.  
  27. $result = mysql_query($query);
  28. }
  29.  
  30. ?>
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 93
Reputation: humbug is an unknown quantity at this point 
Solved Threads: 13
humbug's Avatar
humbug humbug is offline Offline
Junior Poster in Training

Re: Urgent error: Warning: mysql_fetch_array()

 
1
  #3
Oct 28th, 2008
Why the $result = mysql_query($query); on the fourth last line? You don't need the $result = on that line as the mysql_query will return TRUE on success. You are then treating this as a MySQL result resource in mysql_fetch_array($result) (because the expression in the why loop is executed every time the while loop tries to run).
See http://au.php.net/manual/en/function.mysql-query.php

You should get rid of the $result = assignment (or use a different variable name if it is needed) and it should work.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Urgent error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL re

 
0
  #4
Oct 29th, 2008
wow, i can't believe i missed that. yes humbug is right. when you rename that variable it will work fine.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum


Views: 965 | Replies: 3
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC