Search Code

  Home arrow Search Code arrow Search Your Database
SEARCH CODE

Search Your Database
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 13
    2002-01-18

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    This will allow you to search you records in your database. It uses the LIKE string and looks for anything related and prints it. For example if you search for the letter "m" it would print all data fitting the catagory you gave it with the letter "m". [ the llama ] Update made 0a5-25-2001......the search string was not searchinng the entire fileds, only the first word of each record....the change had to do with the LIKE and % strings.....

    By : llama

    ######################################################################
    # The LLama
    # ===========================
    #
    # Copyright (c) 2000 by The LLama (scripts@projectgis.org)
    #
    # Search Records In MYSQL
    #
    # This program is free software.
    ######################################################################

    //This is the form I use to initiate the script (call this find.php)
    <form method=post action="search.php">

    Search For:
    <p>
    User Name: <input type=text name=user size=25 maxlength=25>
    <p>
    Password: <input type=text name=passwd size=25 maxlength=25>
    <p>
    <input type=submit>
    </form>

    //search.php
    <?
    //You should now this but be sure to connect to your database or this is useless. :/
    if ($user == "")
    {$user = '%';}

    if ($passwd == "")
    {$passwd = '%';}
    // $user and $passwd are the two column names I used. Change this to fit your database
    $result = mysql_query ("SELECT * FROM yourtable
    WHERE user LIKE '%$user%'
    AND passwd LIKE '%$passwd%'
    ");

    if ($row = mysql_fetch_array($result)) {

    do {
    PRINT "<b>User Name: </b> ";
    print $row["user"];
    print (" ");
    print ("<br>");
    PRINT "<b>Passwd: </b> ";
    print $row["passwd"];
    print ("<p>");
    PRINT "<b>FirstName: </b> ";
    print $row["firstname"];
    print ("<p>");
    } while($row = mysql_fetch_array($result));
    } else {print "Sorry, no records were found!";}

    //The end result prints the username / passwd / firstname / lastname / ID / email
    //you will have to change these fields also to fit your needs
    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Search Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    SEARCH CODE ARTICLES

    - PHP IP Blocking
    - Search engine with ranking feature
    - Ajax access to Google API
    - Table Searcher
    - Search_It
    - FTP SEARCH
    - Search and Replace class
    - Simple Search on mysql database
    - Search Your Database
    - search_v1.1
    - Database Searching Class

    Developer Shed Affiliates

     



    © 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap