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¶m1="+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.