PHP MySQL ebook
February 12, 2011 – 4:57 pm | No Comment

Hey everyone!!
With this section I hope to share with you resources which I have tried and valued
So you’re new to PHP and want to learn from scratch. Well I was in your position not too …

Read the full story »
SEO Tutorials

Need help with Search Engine Optimisation? This is the place to look for the latest tips and hints with the advice we offer. Keep an eye out here for the latest posts.

PHP Tutorials

Learn how to code with PHP to achieve your goal. In here I aim to show and teach you about little tips and tricks that should enhance your coding abilities

Flash Tutorials

Learn how to use Adobe Flash for your own purposes. Little tips and hints to help you along

Website Development

In here I aim to help you with developing your website from scratch. Come here for various tips and pieces of advice to help you build and improve your website.

Home » PHP Tutorials

Search Page

Submitted by on July 29, 2007 – 3:19 pmNo Comment

OK This tutorial will show you how to make a search page.

Firstly we make a form. I am going to use this:

HTML:
  1. <form action="searchpage.php" method="post">Please enter keyword.
  2.  
  3. <input maxlength="25" name="word" size="25" type="text" /> <input name="Submit" type="submit" value="Submit" /> </form>

This is the form where we will enter the keywords. Now the next step is to make the searchpage.php.

It will look like this

PHP:
  1. // connect to db
  2. $db = mysql_connect("localhostt", "username", "password");
  3. mysql_select_db("dbname",$db);
  4.  
  5. //check something is sent
  6. if ($_POST['word']) {
  7. $word= $_POST["word"];
  8. // search query
  9. $result = mysql_query("SELECT * FROM `table` WHERE `field` LIKE '%$word%'");
  10. $postword = $_POST['word'];
  11. echo "Search Results for: <strong> $postword </strong>
  12. ";
  13. ";
  14. ";
  15. ";
  16. ";
  17. //get results
  18. while($get=mysql_fetch_array($result))
  19. {
  20.  
  21. $date = $get['date'];
  22. $name = $get['name'];
  23. $title= $get['title'];
  24.  
  25. //show results
  26. echo("<strong>$title</strong> was added on <strong>$date</strong> by <strong>$name</strong>");
  27.  
  28. ";
  29. ";
  30. }
  31. // if nothing is sent
  32. }else {
  33. die ("No search word specified");
  34. }
  35.  
  36. ?&gt;

VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

Popularity: unranked [?]

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.