Multiple Criteria Search not working

Discussion in 'PHP' started by jeniferprince, Jun 18, 2010.

  1. #1
    Hi,
    I am trying test a multiple criteria search with two text boxes. That is user will enter values in txt1 and txt2 (or) either one. I want to execute the Select query according to the txt1, txt2 values.

    If both are filled my 'where' condition will be like 'where txt1=$abc and txt2=$cde'. If anyone of the text box is empty (e.g. txt1 is empty) where condition will be 'where txt2=$cde'.

    I have tried this in php with mysql as backend. But getting 500 Internal Server Error.

    How to solve this.. I have added the code below


    <?php
    session_start();
    $check=$_session['user'];
    $con = mysql_connect('localhost','my_user','my_pass'); 
    mysql_select_db('project', $con); //Replace with your MySQL DB Name
    $txt1=$_POST['txt1'];
    $txt2=$_POST['txt2'];
    $sql ="select * from project_master where "
    if(!empty('$txt1'))
    {
    $sql .= "docno='$txt1' and ";
    }
    if(!empty('$txt2'))
    {
    $sql .= "itemno='$txt2' and ";
    }
    $sql = substr($sql,0,-4); \\ to knock off the last and
    $sql .= " order by `docno`";
    while($result = mysql_fetch_array($sql)){
    echo $result[7];
    echo $result[3];
    }
    ?>
    Code (markup):
     
    jeniferprince, Jun 18, 2010 IP
  2. OnurSQL

    OnurSQL Guest

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    500 Errors are irrelevant to SQL coding. You should consult your server administrator.
     
    OnurSQL, Jun 18, 2010 IP
  3. jeniferprince

    jeniferprince Active Member

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #3
    Its working great when i use only

    $sql ="select * from project_master";
     
    jeniferprince, Jun 18, 2010 IP