| | |
Urgent error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL re
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2008
Posts: 3
Reputation:
Solved Threads: 0
Urgent error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL re
0
#1 Oct 27th, 2008
Code:
I keep getting this error:
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.
PHP Syntax (Toggle Plain Text)
<?php define( "DATABASE_SERVER", "blah" ); define( "DATABASE_USERNAME", "blah" ); define( "DATABASE_PASSWORD", "blah" ); define( "DATABASE_NAME", "blah" ); //connect to the database $mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error()); mysql_select_db( DATABASE_NAME ); $sql = 'SELECT * FROM `users`'; $result = mysql_query($sql) or die ('Error: '.mysql_error ()); while($row = mysql_fetch_array($result)) { $hPassword = hash ( sha256, $row['password']); $query = "INSERT INTO new_users (username, password) VALUES('".$row['username']."','$hPassword')"; $result = mysql_query($query); } ?>
I keep getting this error:
PHP Syntax (Toggle Plain Text)
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.
Re: Urgent error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL re
0
#2 Oct 27th, 2008
try:
PHP Syntax (Toggle Plain Text)
<?php define( "DATABASE_SERVER", "blah" ); define( "DATABASE_USERNAME", "blah" ); define( "DATABASE_PASSWORD", "blah" ); define( "DATABASE_NAME", "blah" ); //connect to the database $con = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error()); mysql_select_db( DATABASE_NAME ); $sql = 'SELECT * FROM `users`'; $result = mysql_query($sql,$con) or die ('Error: '.mysql_error()); while($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $hPassword = hash ( sha256, $row['password']); $query = "INSERT INTO new_users (username, password) VALUES('".$row['username']."','$hPassword')"; $result = mysql_query($query); } ?>
Why the
See http://au.php.net/manual/en/function.mysql-query.php
You should get rid of 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. Re: Urgent error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL re
0
#4 Oct 29th, 2008
![]() |
Similar Threads
Other Threads in the PHP Forum
- Previous Thread: Supressing printing if no value
- Next Thread: passing info
Views: 965 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email error execution file files folder form forms function functions google href htaccess html htmlspecialchars image include insert integration ip java javascript joomla jquery limit link links login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote replace script search select server session sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube






