Jump to content

Search function for my website


YNWA

Recommended Posts

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

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?

 

 

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

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.