Welcome to Dream.In.Code
Become a PHP Expert!

Join 150,003 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,352 people online right now. Registration is fast and FREE... Join Now!




Search button in php

 
Reply to this topicStart new topic

Search button in php

Kempy535
21 Nov, 2006 - 01:44 PM
Post #1

New D.I.C Head
*

Joined: 19 Nov, 2006
Posts: 10


My Contributions
I need to make a search feature for my site. I need to make it search through the mysql data base and return the results to another page. I have figured the code for the data base query(I think) and I know how to make the button and form field but I cant figure out how to make the button execute the search code.

This is the code in using for the button
CODE
<form action="search.php" target="mainFrame" method="post">
Search: <input type="text" name="searchf" />
<input type="submit" />
</form>


And this is what i will be using for the mysql search feature
CODE


$result = mysql_query("SELECT * FROM table WHERE item LIKE '%$variable%'");
while($row = mysql_fetch_array($result))
  {
  echo $row['title'];
  echo "<br />";
  }


Im guessing I need to right a method? or something. But im not sure how. Programming is my weakest point mad.gif Any help or idea will be gratefully recived. Many thanks.

This post has been edited by Kempy535: 21 Nov, 2006 - 01:48 PM
User is offlineProfile CardPM
+Quote Post

snoj
RE: Search Button In Php
21 Nov, 2006 - 02:05 PM
Post #2

Fell off the face of the earth
Group Icon

Joined: 31 Mar, 2003
Posts: 3,325



Thanked: 9 times
Dream Kudos: 750
My Contributions
Not seeing the whole script I'm not sure what the problem is.

Forms work almost exactly like the browser does. It's a little different but the HTTP requests are pretty much alike. So you can think of submitting a form as like typing an URL into the address field of your browser and attaching extra information that the form adds.

With that being said...the browser is sent to the page "search.php" with that extra data attached to it in the POST part of the HTTP request. The PHP code in search.php is executed and the output is sent to your browser.

So you have to do these things when search.php is requested:
1. Check if the form has been submitted by checking values in $_POST.
2. Make decision based on that and output data accordingly.
User is offlineProfile CardPM
+Quote Post

Kempy535
RE: Search Button In Php
21 Nov, 2006 - 02:11 PM
Post #3

New D.I.C Head
*

Joined: 19 Nov, 2006
Posts: 10


My Contributions
Thats all I have written. The button form is in a frame and what I want to happen is for people to be able to search my site. I dont understand how to tell the button that when its pressed it needs to run the search code and incude what is written in the 'box' or where to keep the search code so it can be read .
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 08:36PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month