User Profiles [part 02] Fetch_Users() function error.

Post here is you are having problems with any of the tutorials.
Post Reply
Djmann1013
Posts: 11
Joined: Sun Aug 19, 2012 12:19 am
Contact:

User Profiles [part 02] Fetch_Users() function error.

Post by Djmann1013 »

I keep getting this error when viewing the user_list.php file:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/a8913488/public_html/core/inc/user.inc.php on line 13

and it says this at the very bottom left:

Array()

here is the page live:

awsomechat.comuv.com/user_list.php.

Here is my code:
<?php
//user.inc.php file
session_start();

// SQL stuff.
mysql_connect('mysql_host','username','password');
mysql_select_db('database');

// Get users from table
function fetch_users() {
$result = mysql_query('SELECT `user_id` AS `id`, `user_name` AS `username` FROM users');
$users = array();
while(($row = mysql_fetch_assoc($result)) !== false) {
    $users[] = $row;
}
return $users;
}
?>
I would be glad if someone helped.
PHP addict.
drama22
Posts: 22
Joined: Wed May 30, 2012 9:40 am

Re: User Profiles [part 02] Fetch_Users() function error.

Post by drama22 »

Fix this line
while(($row = mysql_fetch_assoc($result)) !== false) {
Djmann1013
Posts: 11
Joined: Sun Aug 19, 2012 12:19 am
Contact:

Re: User Profiles [part 02] Fetch_Users() function error.

Post by Djmann1013 »

Still getting this error:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/a8913488/public_html/core/inc/user.inc.php on line 13
PHP addict.
drama22
Posts: 22
Joined: Wed May 30, 2012 9:40 am

Re: User Profiles [part 02] Fetch_Users() function error.

Post by drama22 »

Djmann1013 wrote:How do I fix it?
while($row = mysql_fetch_assoc($result))
also you may use fetch_array
Djmann1013
Posts: 11
Joined: Sun Aug 19, 2012 12:19 am
Contact:

Re: User Profiles [part 02] Fetch_Users() function error.

Post by Djmann1013 »

I am still getting the error.
PHP addict.
drama22
Posts: 22
Joined: Wed May 30, 2012 9:40 am

Re: User Profiles [part 02] Fetch_Users() function error.

Post by drama22 »

Djmann1013 wrote:I am still getting the error.
past the code after edit..
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: User Profiles [part 02] Fetch_Users() function error.

Post by Temor »

That error means something went wrong with your SQL query. Adding
echo mysql_error();
under the failing query will provide a more detailed description of the error.
function fetch_users() {
$result = mysql_query('SELECT `user_id` AS `id`, `user_name` AS `username` FROM users');

echo mysql_error();

$users = array();
while(($row = mysql_fetch_assoc($result)) !== false) {
    $users[] = $row;
}
return $users;
}
Djmann1013
Posts: 11
Joined: Sun Aug 19, 2012 12:19 am
Contact:

Re: User Profiles [part 02] Fetch_Users() function error.

Post by Djmann1013 »

It works. Thanks.
PHP addict.
Post Reply