如何根据搜索选择特定术语?

So I am wanting the user to be able to search by either keyword or ID number. If they search "test" right now for example it will pull all the entries with test which is what I want it to do for the keyword part of the search. However, I also want the user to be able to search my specific a specific ID# and just pulling that specific entry. I am unsure how I would go about doing this. I tried doing some sort of OR statement but it did not pull any entries.

Search box form

        <div class ="search" id="browse">
                <p> Find your appointment below or search by keyword</p>

                <form id="" class="searchbar" action="searchAppt.php" method="get">
                    <input type="text" name="terms" size="40" class = "sbar" placeholder="Search by issue keyword or ID" oninput="validity.valid||(value='');"
                           onblur="if (this.value == '') {
                                       this.value = 'Enter keyword or ID';
                                   }"
                           onfocus="if (this.value == 'Enter keyword or ID') {
                                       this.value = '';
                                   }"/>&nbsp;&nbsp;
                    <button type="submit" class = "btn">Search</button>
                </form>
            </div>

searchAppt.php

if (filter_has_var(INPUT_GET, "terms")) {
    $terms_str = filter_input(INPUT_GET, 'terms', FILTER_SANITIZE_STRING);
} else {
    echo "There were no appointments found.";
    include ('includes/footer.php');
    exit;
}
            //explode the search terms into an array
            $terms = explode(" ", $terms_str);


            $sql = "SELECT * FROM appointments WHERE 1";
            foreach ($terms as $term) {
                $sql .= " AND email = '". $_SESSION['email'] ."'  AND issue LIKE '%$term%'  OR id ='%term%'
                ";
            }

            $result = $conn->query($sql);

            if ($result->num_rows > 0) {
                echo "<br /><br /><center><h1>My Ticket(s)</h1><br />
                <div class='table'>
                <div class='tr'>
                <div class='td'><b>Ticket #</b></div>
                <div class='td'><b>Issue</b></div>
                <div class='td'><b>Date</b></div>
                <div class='td'><b>Ticket Details</b></div>
                </div>";
                // output data of each row
                while($row = $result->fetch_assoc()) {
                   $starttimepast = strtotime($row["start_time"]); //converts date time received from MySQL into a string
                    $datepast = date("m/d/y", $starttimepast);
                    echo "<div class='tr'>
                    <div class='td'>".$row["id"]."</div>
                    <div class='td'>".$row["issue"]."</div>
                    <div class='td'>".$datepast."</div>
                    <div class='td'><form action='ticketdetails.php' method='post'>
                        <input type='hidden' name='id' value='".$row["id"]."'>
                        <input type='submit' value='Ticket Details'></form>
                    </div>
                    </div>";
                }
                echo "</div>";
                 echo "<br /><center><a href='myProfile.php'><h4>Go back to my profile</h4></a></center>";
                  include ('includes/footer.php');
            } else {
                echo "<br /> <br /><center><h3>Your search <i>'$terms_str'</i> did not match any appointments</h3></center>";
                echo "<center><a href='myProfile.php'><h4>Go back to my profile</h4></a></center>";
                echo "<br />";
                exit;
            }

        ?>
<?php
// clean up resultsets when we're done with them!
$query->close();

// close the connection.
$conn->close();

Perhaps it will help to explicitly group the terms:

  $sql = "SELECT * FROM appointments WHERE email = '" . S_SESSION['email'] . "'";
  $exprs = array();

  foreach ($terms as $term) {
      $exprs[] = "(issue LIKE '%$term%' OR id LIKE '%$term%')";
  }

  if (!empty($exprs)) {
      $sql .= ' AND (' . join(' OR ', $exprs) . ')';
  }

The result in this case will include records that matched any of the terms.

Note: It would be good to use a DB API like laravel/PDO/mysqli to simplify the query building and properly escape the values.