0

With whatever I do (php & meta Content-type headers as utf-8) and all the htmlspecialchars, utf8_de- and encode etc. I just can't seem to insert text the right way into the table. Even returning it in a div, checking with alerts etc. nothing seems to get this right:

This is inserted into the MySQL table:

America’s Greatest Rock ‘N’ Roll Band – have

it should be:

America’s Greatest Rock ‘N’ Roll Band – have 

in the jQuery script I use:

var ch_title = encodeURIComponent(ch_title);
var ch_descr = encodeURIComponent(ch_descr); 

the PHP insert script has:

$ch_descr = "$_POST[ch_descr]";
$ch_descr = nl2br("$ch_descr");
$ch_descr = mysqli_real_escape_string($conn,$ch_descr);

Does anyone know how to get this right?

Solution I used this to solve the problem, including the doctype and headers:

<!DOCTYPE html>
<meta http-equiv="content-type" content="text/html; charset=utf-8">

and for PHP:

header ('Content-type: text/html; charset=utf-8');

$ch_descr = iconv('UTF-8', 'ASCII//TRANSLIT', $ch_descr);
$ch_descr = mysqli_real_escape_string($conn,$ch_descr);
KJS
  • 1,176
  • 1
  • 13
  • 29
  • Also why are you wrapping your variables in double quotes all the time? `$ch_descr = "$_POST[ch_descr]";` can be simply `$ch_descr = $_POST['ch_descr'];` – RiggsFolly Sep 19 '17 at 08:28
  • Thanks, but your comment and duplication article doesn't really tell what to do how to fix this. All the (uni)codes in the database are already correct. – KJS Sep 19 '17 at 09:09
  • Is your php file also utf-8 encoded? – RiggsFolly Sep 19 '17 at 09:11
  • yes it is! with php header and meta – KJS Sep 19 '17 at 09:12
  • No I mean the physical `xxx.php` file i.e. the php source code file – RiggsFolly Sep 19 '17 at 09:13
  • it is now! Changed it with textpad. – KJS Sep 19 '17 at 09:17
  • I fixed it with: $ch_descr = iconv('UTF-8', 'ASCII//TRANSLIT', $ch_descr); $ch_descr = mysqli_real_escape_string($conn,$ch_descr); Thanks for your efforts @RiggsFolly ! – KJS Sep 19 '17 at 09:47

0 Answers0