Search string

Hi All,
I have a form that contains a single text box and a submit button

<form action="ppsearch.php" method="post">
<input type="text" name="searchtext"><br>
<input type="submit" value="Search">

When this is passed over to ppsearch.php I want it to display anything that resembles the text in "searchtext"
But what is the syntax for the query (I'm a real novice at this)

$query  = "SELECT * FROM imageinfo WHERE year LIKE (WHAT DO I PUT HERE?)  LIMIT $limitvalue, $limit";

Thanks in advance


LVL 10
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Assuming that you are just looking for a value in the field year of your table, it would be:

LIKE '%{$_POST['searchtext']}%'

Here the % are wildcards (much like you use * in file systems), and the {} brackets are for giving the start and end of the variable, this is needed because the variable itself ($_POST['searchtext']) has single quotes in it and this would imply the end for the statement because the mysql value also starts and ends with single quotes. So these brackets tell php - from { to } is a variable, don't stop at the single quote. Hope this helps.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
check this

$query  = "SELECT * FROM imageinfo WHERE year LIKE '%".$_GET['searchtext']."%'  LIMIT $limitvalue, $limit";
daleoranAuthor Commented:
many thanks - that worked a treat.

Just to comment on suresh_asp's suggestion: as you can see in the given example of the author, the form method = post, so _GET would not work, that's only for method = get and variables passed through urls. (BTW method = get in forms I would not recommend, should only be used if you have a good reason to)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.