kingmanic2 Posted November 1, 2012 Share Posted November 1, 2012 (edited) 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>"; } ?> Edited November 1, 2012 by kingmanic2 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 1, 2012 Share Posted November 1, 2012 Your query is failing and returning a boolean FALSE value. Echo mysql_error() to see why. Quote Link to comment Share on other sites More sharing options...
kingmanic2 Posted November 1, 2012 Author Share Posted November 1, 2012 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? Quote Link to comment Share on other sites More sharing options...
haku Posted November 1, 2012 Share Posted November 1, 2012 (edited) Why are you using [] around the column names? Edited November 1, 2012 by haku Quote Link to comment Share on other sites More sharing options...
kingmanic2 Posted November 1, 2012 Author Share Posted November 1, 2012 I got rid of all the [] in the sql statement and no errors come up but it doesnt print anything now Quote Link to comment Share on other sites More sharing options...
haku Posted November 1, 2012 Share Posted November 1, 2012 Then this error is fixed, and you have a different one. Turn on error reporting to get an idea of what the problem is. Quote Link to comment Share on other sites More sharing options...
Jessica Posted November 1, 2012 Share Posted November 1, 2012 Post your updated code. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 1, 2012 Share Posted November 1, 2012 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/ Quote Link to comment Share on other sites More sharing options...
kingmanic2 Posted November 1, 2012 Author Share Posted November 1, 2012 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>"; } ?> Quote Link to comment Share on other sites More sharing options...
haku Posted November 1, 2012 Share Posted November 1, 2012 It looks like you may be getting an empty result set. Add some output after your while loop, and see if that is printed to the screen. Quote Link to comment Share on other sites More sharing options...
kingmanic2 Posted November 1, 2012 Author Share Posted November 1, 2012 Yeah, that is printed. It is definiately going through from the form on the other page (which im typing in things that are definately in the database, yet its not printing anything Quote Link to comment Share on other sites More sharing options...
haku Posted November 1, 2012 Share Posted November 1, 2012 Which means that you are getting an empty result set. If you are not getting any errors (and are not suppressing them anywhere), it means that while your SQL syntax is correct it is not finding any results for that query. Quote Link to comment Share on other sites More sharing options...
kingmanic2 Posted November 1, 2012 Author Share Posted November 1, 2012 Its printing things now. Thats so much for the help guys Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.