<div class="box">
            <p>job title <span>*</span></p>
            <input type="text" name="title" value="" placeholder="keyword, category or company" maxlength="200" class="input">
         </div>
         <div class="box">
            <p>job location</p>
            <input type="text" name="location" value="" placeholder="city, zip code,state, country or remote" maxlength="50" class="input">
         </div>
         <button type="submit" name="search" class="btn btn-primary">Search</button>
       </div>`

`<?php
include 'config.php';
if(ISSET($_GET['search'])){
$keyword = $_GET['title'];
$query = mysqli_query($conn, "SELECT * FROM `products` WHERE `title` LIKE '%$keyword%' OR `company` LIKE '%$keyword%' OR `category` LIKE '%$keyword%' OR `description` LIKE '%$keyword%' OR `time` LIKE '%$keyword%' ORDER BY id DESC") or die(mysqli_error());
            
if(ISSET($_GET['search'])){
 $word = $_GET['location'];
 $query = mysqli_query($conn, "SELECT * FROM `products` WHERE `city` LIKE '%$word%' OR `state` LIKE '%$word%' OR `address` LIKE '%$word%' OR `country` LIKE '%$word%'OR `job` LIKE '%$word%' ORDER BY id DESC") or die(mysqli_error());

while($items = mysqli_fetch_assoc($query)){
?>

I have two search field, when I searching not working on both but when I coding one then perfectly. Could please let me know where actual problem. I am new in the sector. Please advice me if you have any alternative option.

[Fixed the formatting for you: it's three ``` to format an entire block of text as code.]

What do you mean by "not working"?

The most serious problem is that you're not using prepared statements to build your query: putting user-supplied material directly into a database query is a surefire way to hose your entire database.

As for "not working", then following through what you've written, you make a query and store it in $query, then immediately throw it away by making another query and storing that in $query as well.

Maybe if you just put all the "...OR LIKE..." parts from both search fields into one query you'd get results that look more like what you want.

Also note that when you do ...where some_field like '%something%'..., the DB is going to have to do a full table read on that some_field column, since wild-carding the start of the matching string means it can't use any index on that field to optimize things. That will mean that as the table gets larger, queries will take proportionally longer.

Another thing to consider is case-sensitivity. You may want to ensure that all data put into those relevant fields is converted to either all lower case or all upper case. Then you can convert the incoming values with PHP's strtoupper() or strtolower() functions as applicable.

A possible work-around for both of those things is to look into using MySQL Full-Text search, which I believe requires some modifications to the table structure to support it. (I don't work in MySQL at all these days, so am not 100% sure.)

Weedpacket

"Maybe if you just put all the "...OR LIKE..." parts from both search fields into one query you'd get results that look more like what you want."
I tried OR like parts of both filed but no one working, Thanks

    NogDog
    I also did called specific column but not working both field, working only last field.

      Well, we haven't seen what you've got now, so it's kind of hard to guess what might be the problem now.

      Weedpacket
      When I keep one search condition off other options work course but when both options run only title field working and location filed not work.

        So when you are filling in both fields, you're still making two queries and throwing one away?

        Weedpacket

        actually working only last onewhile($items = mysqli_fetch_assoc($result)){
        while($items = mysqli_fetch_assoc($query)){

        and when I setup while($items = mysqli_fetch_assoc($query)){
        while($items = mysqli_fetch_assoc($result)){

        Then last one

          So let's go through this.

          kumerbakul if(ISSET($_GET['search'])){

          if(ISSET($_GET['search'])){
          $keyword = $_GET['title'];
          $query = mysqli_query($conn, "SELECT * FROM `products` WHERE `title` LIKE '%$keyword%' OR `company` LIKE '%$keyword%' OR `category` LIKE '%$keyword%' OR `description` LIKE '%$keyword%' OR `time` LIKE '%$keyword%' ORDER BY id DESC") or die(mysqli_error());
                      
          if(ISSET($_GET['search'])){
           $word = $_GET['location'];
           $query = mysqli_query($conn, "SELECT * FROM `products` WHERE `city` LIKE '%$word%' OR `state` LIKE '%$word%' OR `address` LIKE '%$word%' OR `country` LIKE '%$word%'OR `job` LIKE '%$word%' ORDER BY id DESC") or die(mysqli_error());
          
          while($items = mysqli_fetch_assoc($query)){
          if(isset($_GET['search'])) {

          If the search field is set then:

           $keyword = $_GET['title'];

          Get the title field and put it in $keyword. Then

          $query = mysqli_query($conn, ...) or die(...);

          Do a query. Then

          if(isset($_GET['search'])) {

          If the search field is set (and we know it is because we just checked and never finished that part of the code) then:

           $word = $_GET['location'];

          Get the location field and put it in $word. Then

          $query = mysqli_query($conn, ...) or die(...);

          Do a second query. Then

          while($items = mysqli_fetch_assoc($query)){

          Go through the results of the last query made.

          You're not seeing the logical failure here? You make two queries but you are only fetching results from one of them.

          NogDog
          Not working both queries at a time
          actually working only last onewhile($items = mysqli_fetch_assoc($result)){
          while($items = mysqli_fetch_assoc($query)){
          and when I setup while($items = mysqli_fetch_assoc($query)){
          while($items = mysqli_fetch_assoc($result)){
          Then last one

            Trying to D.R.Y. things up a bunch, but totally untested, so buyer beware:

            <?php
            include 'config.php';
            if(isset($_GET['search'])) {
              $wheres = [];
              foreach(['title', 'location'] as $search) {
                if($value = safe_value($conn, $seardh)) { // something was entered for that search
                  foreach(['title', 'company', 'category', 'description', 'time'] as $column) {
                    $wheres[] = "`$column` LIKE '%$value%'";
                  }
                }
              }
              if(count($wheres)) { // at least one of the search fields was set
                $sql = "SELECT * FROM `products` WHERE\n".implode(" OR\n", $wheres)."\nORDER BY id DESC";
            
                // uncomment the following if you want to debug the query:
                // die("<pre>$sql</pre>");
            
                $query = mysqli_query($conn, $sql) or die(mysqli_error());
                while($items = mysqli_fetch_assoc($query)) {
                  // do stuff with result
                }
              } else {
                // whatever you want to do if neither search field was supplied
              }
            }
            
            function safe_value(mysqli $conn, string $name) {
              if(!isset($_GET[$name]) or trim($_GET[$name]) === '') {
                return false;
              }
              // might want to add strtolower() or strtupper to this?
              return mysqli_escape_string($conn, trim($_GET[$name]));
            }

            If you want to force the search term to lower-case, for example, change the last line of that function to:

              return mysqli_escape_string($conn, strtolower(trim($_GET[$name])));

            (I need one of those "buy me a coffee" links or something. 🙂)

            It's difficult to assess from your code whether you understands HTML.

            Where is your form tag?

            Here is an example of what I think you are tyrying to do.
            The form passes control to an action url adminpage.php which displays the inputs

            <?php
            session_start();
            date_default_timezone_set("Europe/London");
            ?>
            
            <!DOCTYPE html>
            <html>
             <head>
              <title>Login</title>
                  <script type="text/javascript">
                
            function subForm(){ subfrm = true; if (name1Obj.value == ""){ alert("Please enter Name Part 1"); name1Obj.focus(); subfrm=false; return; } if (name2Obj.value == ""){ alert("Please enter Name Part 2"); name2Obj.focus(); subfrm=false; return; } if (pwordObj.value == ""){ alert("Please enter Password"); pwordObj.focus(); subfrm=false; return; } if (subfrm==true){ // post to next page formObj.action="adminpage.php"; formObj.submit(); } } </script> </head> <body>
            <form name="form1" method="post" action="adminpage.php" id="form1"> <div> <span id="Label1" style="display:inline-block;height:16px;width:50px;left: 305px; position: absolute; top: 109px; padding-left: 0px; padding-bottom: 0px; margin: 0px; vertical-align: middle; text-indent: 0px; padding-top: 0px; text-align: left;">Part 2</span> <span id="Label1" style="display:inline-block;height:16px;width:173px;left: 73px; position: absolute; top: 109px; padding-left: 0px; padding-bottom: 0px; margin: 0px; vertical-align: middle; border-top-style: none; text-indent: 0px; padding-top: 0px; border-right-style: none; border-left-style: none; letter-spacing: normal; text-align: left; border-bottom-style: none;">Username Part 1</span> <input name="username1" type="text" value="" maxlength="16" id="username1" tabindex="1" style="width:100px;left: 190px; vertical-align: middle; direction: ltr; text-indent: 3px; letter-spacing: normal; position: absolute; top: 104px; height: 20px; text-align: left; z-index: 105;" /> <input name="username2" type="text" value="" maxlength="16" id="username2" style="width:100px;left:350px; vertical-align: middle;position: absolute; top: 104px; height: 20px; text-align: left;" /> <input name="pword" type="text" value="" maxlength="1000" id="pword" tabindex="2" style="width:100px;left: 190px; vertical-align: middle; direction: ltr; text-indent: 3px; letter-spacing: normal; position: absolute; top: 132px; height: 20px; text-align: left; z-index: 103; bottom: 305px;" /> <button id="loginButton" onclick="javascript:subForm();return false;" style="left: 190px; position: absolute; top: 170px; z-index: 107; width:200px; height:25px;">Log in</button> <span id="Label2" style="display:inline-block;height:16px;width:71px;left: 73px; vertical-align: middle; text-indent: 0pt; letter-spacing: normal; position: absolute; top: 135px; text-align: left; z-index: 104;">Password</span> </div> </form> <script type="text/javascript"> formObj = document.getElementById("form1"); name1Obj = document.getElementById("username1"); name2Obj = document.getElementById("username2"); pwordObj = document.getElementById("pword"); </script> </body> </html>

            Heres tha admipage.php

            <?php
            session_start();
            date_default_timezone_set("Europe/London");
            
            
            $username1 = "NOT SET";
            $username2 = "NOT SET";
            $password = "NOT SET";
            
            $contlen = $_SERVER['CONTENT_LENGTH'];
            
            if ($contlen > 0){
                
            $username1 = $_REQUEST['username1']; $username2 = $_REQUEST['username2']; $password = $_REQUEST['pword']; } ?> <!DOCTYPE html> <html> Admin Page
            <table> <tr><td>User name Part 1</td><td><?=$username1 ?></td></tr> <tr><td>User name Part 2</td><td><?=$username2 ?></td></tr> <tr><td>Password</td><td><?=$password ?></td></tr> <tr><td colspan="2">Do what you need to do with this data</td></tr> </table> </html>

            I suggest you master this task first and then add your database access code and work on that.

              NogDog
              Sorry for disturb you. I have a problem when insert pagination. below the error

              Fatal error: Uncaught Error: Call to undefined function safe_value() in

              5 days later

              All that tells me is that somewhere you are trying to call that function in a context where it is not defined; so either you need to define it in that context, or add it to some file that gets included wherever you might need it, or...?

                kumerbakul
                I think the error might be misleading.

                The line

                if($value = safe_value($conn, $seardh))
                

                is an assignment.

                I believe the code is supposed to be a comparison and so should use the == operator

                if($value == safe_value($conn, $seardh))
                

                Try that.

                RayPooley think the error might be misleading.

                The line
                if($value = safe_value($conn, $seardh))

                is an assignment.

                I believe the code is supposed to be a comparison and so should use the == operator

                if($value == safe_value($conn, $seardh))

                Try that.

                That wouldn't make a difference. The value of the assignment is still either whatever safe_value() returns, so the if() statement still takes the same branch. The only difference is that $value is also assigned the same value, which is a good thing, since it is then used later in the then branch.

                Using == wouldn't fix anything because now you're comparing the return value of safe_value() with the value of a variable that doesn't even have a value yet. (You'd get an Undefined variable warning, and take the "safe value" branch only in the situation when safe_value() returns false.)

                And, of course, it wouldn't fix the reported problem that the safe_value function wasn't even found in the first place.

                I do notice another bug, though: safe_value() will return a falsy value if $_GET[$name] is '0'. It may not be relevant in this instance (what does the "time" column contain if time LIKE '%$value%' is useful?) but since we're retrieving every record that contains a 1 in the description it would be churlish to not be doing the same for 0. I think the return value should be checked more carefully:

                if(($value = safe_value($conn, $search)) !== false)

                or even separate testing-for-content and escaping-for-query into two separate functions.

                But yes, like @NogDog says, if your pagination thing is on a different page then you'll need to get the function there as well, preferably by putting it another file and including it on every page you need it. If that's not what you're doing you'll need to explain what you are doing.