|
-
Apr 27th, 2006, 08:27 PM
#1
Thread Starter
Frenzied Member
Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
Hi all i got a php script that works perfectly in my localhost but when i use it in a site which is in remote i get the following error:
Code:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home2/method/public_html/music/singerIndex.php on line 72
When i load the page no output and i get the above error. Is there any connection problem here? or sql syntax ?I be happy if an expert tell me how to fix it.Thanks
Code:
<?php
//alone script that reads folder but but not subfolder and wirtes it file name to db
// change below is your assigned mySQL username
$user = "root";
// change to the pw below is your assigned mySQL password
$pw = "";
// change to the database you have permission to connect to
$db = "method_music";
//mysql_connect("localhost", "root", "");
$mysql_access = mysql_connect("localhost", $user, $pw);
mysql_select_db($db, $mysql_access);
$query = "select distinct artist from songs order by artist";
$result = mysql_query($query);
//echo $query;
//exit();
?>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<title>Untitled </title>
</head>
<body>
<br>
<br>
<br>
<br>
<br>
<table border="1" cellspacing="1" width="100%"
bordercolorlight="#008ED2" id="table1"
style="BORDER-COLLAPSE: collapse">
<tr>
<td colspan="3" bgcolor="#323E8D"><p align="center"><font
color="#FFFFFF"><b>:.Singers ..:</b></font></p>
</td>
</tr>
<tr>
<td valign="top"><table border="0" cellpadding="2">
My code. The red line shows the line 72:
<?
//this line for dropdownbox
$option = "";
$numbers=0;
while($row = mysql_fetch_assoc($result)) ==> error point
{
$numbers++; // counting number of records
//This 2 line for drop downbox
extract ($row);
$option .= "<option value=\"$artist\">$artist</option>\r\n";
//echo "<br>Id : {$row['id']} <br>" .
// "filename :{$row['filename']} <br>" .
// "artist : {$row['artist']} <br>" .
// "album : {$row['album']} <br>" .
// "title : {$row['title']} <br><br>";
?>
<tr>
<td style="BORDER-BOTTOM-STYLE: dotted"><a
href="albums.php?albumname=<?=strval( $row['artist'] );?>"><? echo $numbers; ?>=><?=strval( $row['artist'] );?></a> [<a
href="javascript:newWindow('RateSingers.php?SingerID=1378')">Rate
Me</a>] Hits:<b>???</b></td>
</tr>
<?
}
?>
-
Apr 27th, 2006, 09:05 PM
#2
Fanatic Member
Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
Try this in your query:
Code:
$query = "select distinct `artist` from `songs` order by `artist`";
noister
<advertising link removed by moderator>
-
Apr 27th, 2006, 09:16 PM
#3
Thread Starter
Frenzied Member
Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
 Originally Posted by noielen
Try this in your query:
Code:
$query = "select distinct `artist` from `songs` order by `artist`";
Thank u for u reply. Unfortuently same error !! Is it connection problem ?
-
Apr 27th, 2006, 09:22 PM
#4
Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
You must have no data in your database.
-
Apr 27th, 2006, 09:29 PM
#5
Fanatic Member
Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
what about:
Code:
$query = "select distinct(artist)... order by artist asc"
noister
<advertising link removed by moderator>
-
Apr 27th, 2006, 09:32 PM
#6
Thread Starter
Frenzied Member
Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
 Originally Posted by penagate
You must have no data in your database.
i check mysql db using phpmyadmin and i see there are data!
-
Apr 27th, 2006, 09:43 PM
#7
Thread Starter
Frenzied Member
Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
 Originally Posted by noielen
what about :
Code:
$query = "select distinct(artist)... order by artist asc"
Thank u for u reply.same error!
-
Apr 27th, 2006, 09:52 PM
#8
Fanatic Member
Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
i have this error before, i just put `` before and after of my fieldnames and tables. now i used that all in my queries...
noister
<advertising link removed by moderator>
-
Apr 27th, 2006, 09:52 PM
#9
Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
after
PHP Code:
$result = mysql_query($query);
add
PHP Code:
if (!is_resource($result)) echo mysql_error();
-
Apr 27th, 2006, 10:15 PM
#10
Thread Starter
Frenzied Member
Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
 Originally Posted by penagate
after
PHP Code:
$result = mysql_query($query);
add
PHP Code:
if (!is_resource($result)) echo mysql_error();
Thank u for u reply. I get this error:
No database selected
I do not know what i am doing wrong!!
-
Apr 27th, 2006, 10:19 PM
#11
Fanatic Member
Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
and thats....... obviously in your connection.
noister
<advertising link removed by moderator>
-
Apr 27th, 2006, 10:20 PM
#12
Fanatic Member
Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
try this
Code:
$link = mysql_select_db($db, $mysql_access);
$query = "select distinct artist from songs order by artist";
$result = mysql_query($query, $link);
i'm not sure with this just try it.
noister
<advertising link removed by moderator>
-
Apr 27th, 2006, 11:17 PM
#13
Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resour
I think I know what it is, on a hosted machine the DB name is usually prefixed with your username, e.g.
PHP Code:
$db = 'tony007_method_music';
Last edited by penagate; Apr 28th, 2006 at 05:09 AM.
-
Apr 28th, 2006, 12:05 AM
#14
Fanatic Member
Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
 Originally Posted by penagate
I think I know what it is, nn a hosted machine the DB name is usually prefixed with your username, e.g.
PHP Code:
$db = 'tony007_method_music';
mybe
noister
<advertising link removed by moderator>
-
Apr 28th, 2006, 01:03 AM
#15
Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resour
You should be error checking every call to mysql which could fail. mysql_select_db() is the same as calling mysql_query('use dbname').
Code:
if (! mysql_select_db($db)) {
echo(mysql_error());
die;
}
if (! ($result = mysql_query($query)) {
echo(mysql_error());
die;
}
Last edited by visualAd; Apr 28th, 2006 at 09:25 AM.
-
Apr 28th, 2006, 05:06 AM
#16
Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|