Search criteria

Discussion in 'PHP' started by sangpo, Nov 27, 2012.

  1. #1
    sir and madam

    I have files named as new.php and new_ac.php for search records from table. I have 2 tex boxes (ie one for search by first name and othe r for search by last name. Search by last name is working correctly but search by first name, all records are being displays (ie not filtering) follwing is my html and php codes. Please kindly tell me where is the mistakes.



    <html>

    <body>




    <form name="form1" method="post" action="new_ac.php">
    Seach by first name:<input type="text" name="fname">
    <br>
    Seach by last name:<input type="text" name="lname">


    <input type="submit" name="Submit" value="Searrch"></td>


    </form>

    </body>



    <?php


    $db_host="127.0.0.1";
    $db_user="root";
    $db_password="";
    $db_name="test";
    $connection=@mysql_connect($db_host, $db_user, $db_password) or die("Error connecting to server");
    $db=mysql_select_db($db_name,$connection) or die("Error connecting to database");


    $searchfname=$_POST["fname"];
    $searchlname=$_POST["lname"];




    $data=mysql_query("SELECT * FROM users WHERE fname like '$searchfname%'");

    $data=mysql_query("SELECT * FROM users WHERE lname like '$searchlname%'");




    while($result=mysql_fetch_array($data))


    {


    echo $result['fname'];
    echo"";


    echo"<br>";
    echo $result['lname'];
    echo"<br>";
    echo"<br>";


    }
    ?>

    Sangpo
     
    sangpo, Nov 27, 2012 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    two times $data is one time the real $data

    :) hope you'll see your fault!
     
    EricBruggema, Nov 27, 2012 IP
  3. sangpo

    sangpo Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Dear Eric,

    Thank you very much for finding my fault. It works well .

    sangpo from bhutan
     
    sangpo, Nov 27, 2012 IP