PHP MySQL search with multiple criteria

前端 未结 3 486
温柔的废话
温柔的废话 2021-01-23 15:04

I have a search form in a website and would like to have several search terms which is input by the user to perform db search, terms as below:

  • Keywords
  • Pr
3条回答
  •  日久生厌
    2021-01-23 15:17

    if(isset($_SESSION['login']))
    {
     echo "";
    
    
     }
     else
     {
        echo " ";
     }
    
    $con=  mysql_connect("localhost","root","");
      $d=mysql_select_db("matrimonial",$con);
       $gender=$_POST['gender'];
      $age1=$_POST['age1'];
      $age2=$_POST['age2'];
      $city=$_POST['city'];
      $subcast=$_POST['subcast'];
      $result=mysql_query("select * from matri where gender='$gender' and age between '$age1' and '$age2' and city='$city' and subcast='$subcast'");
    
    if($gender && !empty($gender))
    {
     $result .= " AND `gender`='$gender'";
    }
    
    if($age1 && !empty($age1)){
            $result .= " AND `age`='$age1'";
        }   
     if($age2 && !empty($age2)){
           $result .= " AND `age`='$age2'";
        }  
    
     if($city && !empty($city)){
           $result .= " AND `city`='$city'";
        }  
    
      if($subcast && !empty($subcast)){
           $result .= " AND `subcast`='$subcast'";
        }  
    
       $result .= " select * from ";
    
       $sql = $mysql->query($result);
    how to run this code
    

提交回复
热议问题