-1

I'm having a problem with an SQL database in combination with JavaScript, and it's really awkward.

HTML on page "configuration.php"

<input id="action_description" type="text"/>
<input id="send" type="button" onClick="addAction()"/>

JavaScript on script.js

function addAction(){
      var action = document.getElementById('action_description').value;
      if (action == ""){
      window.alert("error");
      }
      else {
      xmlhttp.open("GET","doConfig.php?action=2&param1="+action,false);
      xmlhttp.send();
     }
}

I do actually the xmlhttp for Microsoft or other, but this is not of interest to the problem.

PHP on doConfig.php

include('db.php');
mysqli_set_charset($link,'utf8');
$action= $_GET['action'];
switch ($action){
     case '2':
              $text = $_GET['param1'];
              $sql = "INSERT into actions (text) VALUES ('$text')";
              echo $sql;
              mysqli_query($link,$sql);
     break;
}

Database

Database in XAMPP with phpMyAdmin. Charset UTF8_bin.

The column is named "text" and is format "text (255)".

Problem:

Now the problem is, when I use characters from my country (ä ü ö ), the database messes up those. For example the character Ä gets displayed as an A and a quarter symbol.

But, when I copy the echo $sql, for example "INSERT into actions (text) VALUES ('ähä?)" to my phpMyAdmin console into the SQL-Field, then it works perfectly, and the character gets displayed right.

halfer
  • 19,824
  • 17
  • 99
  • 186
sgtBear
  • 61
  • 2
  • 10
  • 1
    Save your scripts in UTF-8 encoding and your webcontent like `` btw why `utf8_bin` and not `utf8mb4_unicode_ci` for example? – Daniel W. Jun 09 '14 at 19:32
  • doesnt work. whats the difference? the database choosed that format, not me. – sgtBear Jun 09 '14 at 19:40

1 Answers1

0

If the text is right in your database use the header function of php to display utf-8 characters on your page:

header('Content-Type: text/html; charset=utf-8');
S.Pols
  • 3,414
  • 2
  • 21
  • 42