2

so basically i have the following code in php:

mysqli_query($connect,"SET NAMES 'utf8'");
mysqli_query($connect,"SET CHARACTER SET utf8");
mysqli_query($connect,"SET COLLATION_CONNECTION = 'utf8_unicode_ci'");

in html:

<form method="post" accept-charset="utf-8">
 <div class="input-group">
   <input id="name" type="text" class="form-control" name="name"  value="<?php print $data["name"]; ?>" placeholder="<?php print $data["name"]; ?>">
                                                        </div>
</form> 

javascript:

var name = $('#name').val();
  var surname = $('#surname').val();
  var phone_number = $('#phone_number').val();
  var GSM = $('#GSM').val();
  var mail = $('#mail').val();
  var work = $('#work').val();
  var pharmacy_name = $('#pharmacy_name').val();
  var pharmacy_id = $('#pharmacy_id').val(); 
  if($.trim(name).length > 0 && $.trim(surname).length > 0 && $.trim(phone_number).length > 0 && $.trim(GSM).length > 0 && $.trim(mail).length > 0 && $.trim(work).length > 0 && $.trim(pharmacy_name).length > 0 && $.trim(pharmacy_id).length > 0)
  {
   $.ajax({
    url:"editProfileAction",
    method:"POST",
    data:{name:name, surname:surname},
    cache:false,
....

i am using ajax to edit mysql db but characters such as ıİ,ğĞ are shown as ?? but characters 'çÇüÜ' works fine i tried 3 4 hours trying to fix it i couldn't find an error

M.Fakhri
  • 176
  • 1
  • 3
  • 16
shiv zuh
  • 125
  • 11
  • http://www.phptherightway.com/#php_and_utf8 and utf8mb4 for the database – Michael GEDION Aug 22 '17 at 13:45
  • I have previously written [**an answer about UTF-8 encoding**](https://stackoverflow.com/a/31899827/4535200) that contains a little checklist, that will cover *most* of the charset issues in a PHP/MySQL application. There's also a more in-depth topic, [UTF-8 All the Way Through](https://stackoverflow.com/q/279170/4535200). Most likely, you'll find a solution in either one or both of these topics. – Qirel Aug 22 '17 at 13:51

1 Answers1

0

Read this post from php the right way. For a complete UFT8 support you need to set:

At the php level: Put it at the top of your PHP script

 <?php
 // Tell PHP that we're using UTF-8 strings until the end of the script
mb_internal_encoding('UTF-8');

At the database level:

Your databse collation must be set : utf8mb4 character set and collation.

utf8mb4 character set for complete UTF-8 support, not the utf8 character set!

At the browser level, include

 // Tell PHP that we'll be outputting UTF-8 to the browser
mb_http_output('UTF-8');

and for the html part

<meta charset="UTF-8">
Michael GEDION
  • 879
  • 8
  • 16
  • it works in html output but now values in my database gives are such as ıİ i used utf8mb4 as you said – shiv zuh Aug 22 '17 at 14:17