Jump to content

Warning: Mysql_Fetch_Array() Expects Parameter 1 To Be Resource, Boolean


kingmanic2

Recommended Posts

I cant seem to get this going and displaying properly. I'm getting the variable searchbar from another page which has a form on it that the user can input. When I input something that I diffidently know is in the database I get the error:

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\Site]search.php on line 42

 

Any help would be much appreciated.

Thanks

 

<?php


$dbname = "assignment2";
$dbhost = "127.0.0.1";
$dbuser = "root";
$dbpwd = "";
$search = $_GET['searchbar'];


$link = mysql_connect($dbhost, $dbuser, $dbpwd);
mysql_select_db($dbname);


$sql = "SELECT comic.image_thumbnail, comic.title, comic.description, comic.volume, artist.name AS artist_name, author.name AS author_name, genre.type, publisher.name AS publisher_name, comic.publication_date
FROM ((publisher INNER JOIN (genre INNER JOIN (comic INNER JOIN (comic_author INNER JOIN author ON comic_author.[author_id] = author.[author_id]) ON comic.[comic_id] = comic_author.[comic_id]) ON genre.[genre_id] = comic.[genre_id]) ON publisher.[publisher_id] = comic.[publisher_id]) INNER JOIN comic_artist ON comic.[comic_id] = comic_artist.[comic_id]) INNER JOIN artist ON comic_artist.[artist_id] = artist.[artist_id] WHERE comic.title like '%$search' OR artist.name like '%search' OR author.name like '%$search' OR publisher.name like '%$search'" ;


$result = mysql_query($sql);


while ($row = mysql_fetch_array($result)){               //This is line 42
echo "<img height=200 align=center src=".$row['image_thumbnail'].">". "<br>". //comic
'Title: '.$row['title']."<br>". //comic
'Description: '.$row['description']."<br>". //comic
'Volume: '.$row['volume']."<br>". //comic
//'Artist: '.$row['name']."<br>". //comic -> comic_artist -> artist
//'Author: '.$row['author']."<br>". //comic -> comic_author -> author
'Genre: '.$row['genre_id']."<br>". //comic -> genre
'Publisher: '.$row['publisher_id']."<br>". //comic -> publisher
'Publication Date: '.$row['publication_date']."<br>". //comic

"<br>";
}
?>

I now get this:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[author_id] = author.[author_id]) ON comic.[comic_id] = comic_author.[comic_id])' at line 2

 

And i dont see the problem with it?

You might want to take a look at the following thread (it would appear someone else in your class is having the same problems) - http://forums.phpfreaks.com/topic/270110-having-some-problems-with-my-searchphp/

Updated code:

 

<?php


$dbname = "assignment2";
$dbhost = "127.0.0.1";
$dbuser = "root";
$dbpwd = "";
$search = $_GET['searchbar'];


$link = mysql_connect($dbhost, $dbuser, $dbpwd);
mysql_select_db($dbname);


$sql = "SELECT comic.image_thumbnail, comic.title, comic.description, comic.volume, artist.name AS artist_name, author.name AS author_name, genre.type, publisher.name AS publisher_name, comic.publication_date
FROM ((publisher INNER JOIN (genre INNER JOIN (comic INNER JOIN (comic_author INNER JOIN author ON comic_author.author_id = author.author_id) ON comic.comic_id = comic_author.comic_id) ON genre.genre_id = comic.genre_id) ON publisher.publisher_id = comic.publisher_id) INNER JOIN comic_artist ON comic.comic_id = comic_artist.comic_id) INNER JOIN artist ON comic_artist.artist_id = artist.artist_id WHERE comic.title like '%$search' OR artist.name like '%search' OR author.name like '%$search' OR publisher.name like '%$search'" ;


$result = mysql_query($sql);


while ($row = mysql_fetch_array($result)){
   echo "<img height=200 align=center src=".$row['image_thumbnail'].">". "<br>". //comic
 'Title: '.$row['title']."<br>". //comic
 'Description: '.$row['description']."<br>". //comic
 'Volume: '.$row['volume']."<br>". //comic
 'Artist: '.$row['name']."<br>". //comic -> comic_artist -> artist
 'Author: '.$row['author']."<br>". //comic -> comic_author -> author
 'Genre: '.$row['genre_id']."<br>". //comic -> genre
 'Publisher: '.$row['publisher_id']."<br>". //comic -> publisher
 'Publication Date: '.$row['publication_date']."<br>". //comic

 "<br>";
   }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.