3

I have a select statement which should select all data in the database which equals to a Arabic input, I've set database's collation to utf8_general_ci and tables column as them for sure. And at the file

$conn = mysqli_connect($mysql_host, $mysql_user, $mysql_password, $mysql_database); 
mysqli_query($conn, "set names 'utf8'");
mysqli_query($conn, "SET character_set_results=utf8");
mb_http_output('UTF-8'); 
mb_internal_encoding('UTF-8');
mb_http_input('UTF-8');
mb_language('uni');
mb_regex_encoding('UTF-8');
ob_start('mb_output_handler');
mb_language('uni'); 
mb_internal_encoding('UTF-8');
mysqli_set_charset($conn, "utf8");

And the code of the search

$question = $_REQUEST['question'];
$table = $_REQUEST['subject'];
if(empty($question)) {
echo "Type a question!"; }
$qe = mysqli_escape_string($conn, $question);
$full = "SELECT * FROM $table WHERE question LIKE '%$qe%'";
$fullQ = mysqli_query($conn, $full);
if(!$fullQ) {
echo mysqli_error($conn);
}
echo "<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>";
printf(nl2br("\n%u\n"), mysqli_num_rows($fullQ));
while($row = mysqli_fetch_assoc($fullQ)) {
printf(nl2br("\n%s\n"), $row['question']);
}

It works if I print all the data without using WHERE and it also prints the SQL syntax after it is sent from the first page to the second one right with the correct Arabic characters. But it always return 0 rows.

Ahmed Nezar
  • 77
  • 1
  • 10
  • I doubt that meta element will be doing anything if you're outputting after text on the body of the page. What does the actual output HEAD of your HTML document look like? (Is the entire "view source" of your web page small enough to post?) – Matt Gibson Oct 20 '15 at 12:54

1 Answers1

-1

If your database saved in arabic then set up connection string to the following

$con1 = mysqli_connect($HOSTURL,$DBUSER,$DBPASSWORD,$DBNAME);

    // Check connection
        if (mysqli_connect_errno())
          {
          echo "Failed to connect to MySQL: " . mysqli_connect_error();
            die('');
          }
        mysqli_query($con1,"SET NAMES utf8");   
      //else{echo "Connection Done";}

if your database is not encoded then you do not have to set utf8 in your connection string.

Mohammed Ali
  • 696
  • 3
  • 9
  • 22