Whats wrong with this code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mmarif4u
    New Member
    • Sep 2006
    • 23

    Whats wrong with this code

    Hi Everyone.

    I have html page coding:
    HTML coding.....
    ---------------------------------------------------
    <h2>Search</h2>
    <form name="search" method="post" action="Search. php">
    Seach for: <input type="text" name="find" /> in
    <Select NAME="field">
    <Option VALUE="fname">F irst Name</option>
    <Option VALUE="lname">L ast Name</option>
    <Option VALUE="info">Pr ofile</option>
    </Select>
    <input type="hidden" name="searching " value="yes" />
    <input type="submit" name="search" value="Search" />
    </form>
    --------------------------------------------------

    Now Php Which have to search the database & Print results.
    PHP Coding.....
    --------------------------------------------------
    <?
    if ($searching =="yes")
    {
    echo "<h2>Result s</h2><p>";

    if ($find == "")
    {
    echo "<p>You forgot to enter a search term";
    exit;
    }
    mysql_connect(" localhost", "root", "") or die(mysql_error ());
    mysql_select_db ("db") or die(mysql_error ());

    $find = strtoupper($fin d);
    $find = strip_tags($fin d);
    $find = trim ($find);

    $data = mysql_query("SE LECT * FROM users WHERE upper($field) LIKE'%$find%'") ;

    while($result = mysql_fetch_arr ay( $data ))
    {
    echo $result['fname'];
    echo " ";
    echo $result['lname'];
    echo "<br>";
    echo $result['info'];
    echo "<br>";
    echo "<br>";
    }

    $anymatches=mys ql_num_rows($da ta);
    if ($anymatches == 0)
    {
    echo "Sorry, but we can not find an entry to match your query<br><br>";
    }

    echo "<b>Searche d For:</b> " .$find;
    }
    ?>

    --------------------------------------------

    The problem is that it cannot display the Results.
    Whats wrong with this code.
    Can anyone help me.
    Thanks.
  • vssp
    Contributor
    • Jul 2006
    • 268

    #2
    Are u get the post value first and then working fine

    Comment

    • bevort
      New Member
      • Jul 2006
      • 53

      #3
      I think it has more to do with the $find var.
      You check it against the upper() value in the database. But in this code you can not be sure thet the user typed only uppercase.
      Make $find upper as well when comparing in the SQL

      Next skip the hidden value "searching" and check on the submitbutton "Search"
      like if ($Search) .......
      this makes sure that hte user realy pressed the search button

      Check also the query string you send to the database bu echoing it on screen.
      Then check if this works in a query tool like PHPMyAdmin.

      If you do not get results there you won't get them on screen.

      Comment

      Working...