1

ここに画像の説明を入力

以下のコードは、テキストボックスに入力された従業員番号または名に基づいて従業員を検索しますが、名がアラビア語であり、一致しません。画像が添付されていて、ブラウザ上でアラビア語が優先的に表示されていますが、テキストボックスで検索されているわけではありません。理由はわかりません。

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <html> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <head> 
        <meta  http-equiv="Content-Type" content="text/html;  charset=iso-8859-1"> 
        <title>Search  Contacts</title> 
        <link rel="stylesheet" href="css/insert.css" /> 
        <link rel="stylesheet" href="css/navcss.css" />
      </head> 
      <body> 
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <div class="maindiv">
<?php include("includes/head.php");?>
<?php include("menu.php");?>

        <!--HTML form -->
            <div class="form_div">
        <h3>Search  Records:</h3> 
        <p>You  may search by Employee Number</p> 
        <form  method="post" action="search.php?go"  id="searchform"> 
          <input  type="text" class="input" name="emp_number"> 
          <input  type="submit" class="input" name="submit" value="Search"> 
        </form>

<?php 

include 'connect-db.php';
    //do  something here in code 

      if(isset($_POST['submit'])){ 
      if(isset($_GET['go'])){ 
      if(preg_match("/^[a-zA-Z0-9,]+$/", $_POST['emp_number'])){ 
      //if(preg_match("/\p{Arabic}/u", $_POST['first_name'])){
      $emp_number=$_POST['emp_number']; 
      //$first_name=$_POST['first_name']; 
      //connect  to the database 
      //$db=mysql_connect  ("localhost", "root",  "") or die ('I cannot connect to the database  because: ' . mysql_error()); 
      //-select  the database to use 
      //$mydb=mysql_select_db("mydb"); 
      //-query  the database table 
      //mysqli_query($connection,"SET CHARACTER SET utf8");
      $sql="SELECT  * FROM employees WHERE emp_number LIKE '%" . $emp_number .  "%' OR first_name LIKE '%" . $emp_number."%'"; 
      //-run  the query against the mysql query function . $name .
      $result=mysql_query($sql); 
      //-create  while loop and loop through result set 
      while($row=mysql_fetch_array($result)){ 
              $FirstName  =$row['first_name'];

       echo "<table border='1' cellpadding='10'>";
       echo "<tr><th>First Name</th> <th>Last Name</th><th>Employee Number</th><th>Department</th><th>Email</th><th>Total Printers</th><th>Total Scanners</th><th>Total PCs</th><th>Total Telephones</th></tr>";        

      //-display the result of the array 
      echo "<tr>";
      echo '<td>' . $row['first_name'] . '</td>';
      echo '<td>' . $row['last_name'] . '</td>';
      echo '<td>' . $row['emp_number'] . '</td>';
      echo '<td>' . $row['department'] . '</td>';
      echo '<td>' . $row['email'] . '</td>';
      echo '<td>' . $row['total_printers'] . '</td>';
      echo '<td>' . $row['total_scanners'] . '</td>';
      echo '<td>' . $row['total_pc'] . '</td>';
      echo '<td>' . $row['total_phones'] . '</td>';
      echo '<td class="forscreen"><a href="view-one.php?emp_id=' . $row['emp_id'] . '">View</a></td>'; 
      echo '<td class="forscreen"><a href="edit.php?emp_id=' . $row['emp_id'] . '">Edit</a></td>'; 
      echo '<td class="forscreen"><a href="delete4msearch.php?emp_id=' .$row['emp_id'] . '">Delete</a></td>'; 
      echo '<td class="forscreen"><a href="view-aceessory.php?emp_number=' .$row['emp_number'] . '">View Accessories</a></td>';
      echo '<td class="forscreen"><a href="equipments.php?emp_number=' .$row['emp_number'] . '">Add Accessories</a></td>';
      //echo '<button class="btnPrint" type="submit" value="Submit" onclick="window.print()">Print</button>';
      //echo '<button class="btnPrevious" type="submit" value="Submit" onclick="history.back(); return false;">Return to previous page</button>';


      /*echo "<ul>\n"; 
      echo "<li>" . "<a  href=\"search.php?first_name=$FirstName\">"   .$FirstName . "</a></li>\n"; 
      echo "</ul>"; */
      echo "</tr>";

      } 
      // close table>

echo "</table>";

      } 
      else{ 
      echo  "<p>Please enter a search query</p>"; 
      } 
      }

      }


    ?>  

    <div class="forscreen">
    <br />

<button class="btnPrint" type="submit" value="Submit" onclick="window.print()">Print</button>
<button class="btnPrevious" type="submit" value="Submit" onclick="history.back(); return false;">Return to previous page</button>

</div>


</div>
</div>  
      </body> 
    </html> 
4

2 に答える 2

0

これは最新バージョンの PHP では必要ないかもしれませんが、ファイルの最初の行に次を追加します。

<?php
    header('Content-Type: text/html; charset=utf-8');
    mb_internal_encoding('UTF-8');
    mb_http_output('UTF-8');
?>
于 2016-11-02T18:52:08.437 に答える