2 Replies - 38140 Views - Last Post: 21 November 2006 - 03:11 PM Rate Topic: -----

#1 Kempy535  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 19-November 06

Search button in php

Posted 21 November 2006 - 02:44 PM

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
<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

$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 :angry: Any help or idea will be gratefully recived. Many thanks.

This post has been edited by Kempy535: 21 November 2006 - 02:48 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Search button in php

#2 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: Search button in php

Posted 21 November 2006 - 03:05 PM

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.
Was This Post Helpful? 0
  • +
  • -

#3 Kempy535  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 19-November 06

Re: Search button in php

Posted 21 November 2006 - 03:11 PM

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 .
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1