YNWA Posted April 25, 2008 Share Posted April 25, 2008 I am currently designing a website for my University Deanery as part of my degree. I am using MySQL and PHP. The site is for students to add their own books for others to buy. I want to have a search feature, where users can search my website (database) for certain books. My database table is called 'review', I have an 3 columns 'author', 'bookTitle' and 'bookDescription' I want my user to be able to search for any word , and the search function to search my database and throw up the results of that search. I have tried a few of the online scripts but I keep coming un stuck, i think it is to do with my variables but I am not 100% sure. If anyone could help, that would be great. Thanks Will Link to comment https://forums.phpfreaks.com/topic/102883-search-function-for-my-website/ Share on other sites More sharing options...
zenag Posted April 25, 2008 Share Posted April 25, 2008 $name=$_post["search"]; SELECT * FROM `review` WHERE author like '$name' or 'bookTitle' like '$name' or bookDescription like '$name' Link to comment https://forums.phpfreaks.com/topic/102883-search-function-for-my-website/#findComment-526997 Share on other sites More sharing options...
YNWA Posted April 25, 2008 Author Share Posted April 25, 2008 Thanks, I get this: Parse error: syntax error, unexpected '`' in C:\wamp\www\index.php on line 76 Here is what is in the code: <h3>Search</h3> <h3>Search</h3> <?php $name=$_post["search"]; "SELECT * FROM `review` WHERE author like ( '$name' or 'bookTitle' like '$name' or 'bookDescription' like '$name' )"; ?> Any ideas? Link to comment https://forums.phpfreaks.com/topic/102883-search-function-for-my-website/#findComment-526999 Share on other sites More sharing options...
YNWA Posted April 25, 2008 Author Share Posted April 25, 2008 Anyone expand on this? Thanks Link to comment https://forums.phpfreaks.com/topic/102883-search-function-for-my-website/#findComment-527381 Share on other sites More sharing options...
dptr1988 Posted April 25, 2008 Share Posted April 25, 2008 You SQL query is all messed up. Here is an example: <?php $name=$_post["search"]; $query = "SELECT * FROM `review` WHERE `author` LIKE '%{$name}%' OR `bookTitle` LIKE '%{$name}%' " . " OR `bookDescription` LIKE '%{$name}%' "; ?> Also you weren't assigning that query string to a variable. http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html Link to comment https://forums.phpfreaks.com/topic/102883-search-function-for-my-website/#findComment-527397 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.