ETSoft Posted July 16, 2021 Share Posted July 16, 2021 (edited) Hi , I'm trying to upload data to a mysql database through a script but although the charset is set right in the database the uploaded data is in the wrong format, it needs to be in German (if i do it manually the data is correct) : <?php if(isset($_POST['submit'])){ $DBCon = new mysqli("localhost", "", "", ""); $result = $DBCon->query($_POST['query_input']); echo "<span style='color: green;'>Hochladen in Datenbank bereit!! </span>"; } ?> <!DOCTYPE html> <html lang="en-US"> <head> <title> Daten in die Cloud-Datenbank hochladen</title> </head> <body> <table style=width:100%> <tr> <img src="TACS.png"> </tr> <tr> <h2> Daten in die Cloud-Datenbank hochladen</h2> <form action="" method="post"> <div> <label style="vertical-align: top;">Füge den Befehl hier ein : </label> <textarea name="query_input" rows="30" cols="100" required=""></textarea> </div> <BR> <div> <input type="submit" name="submit" value="Senden"> </div> </form> </tr> </body> </html> Could someoen assist me? Thanks in advance Erwin Edited July 16, 2021 by ETSoft Quote Link to comment Share on other sites More sharing options...
requinix Posted July 16, 2021 Share Posted July 16, 2021 There are multiple places where character encoding matters. Make sure you have UTF-8 set: - For the database's default charset (use SHOW CREATE DATABASE) - For every table's default charset, which is inherited from the database at the time it was created (use SHOW CREATE TABLE) - For every column's charset, which is inherited from the table at the time it was created - For all connection related settings (use SHOW VARIABLES LIKE '%char%') - if you can configure everything at the server level that's best, otherwise you'll have to configure some of them in your code - For your PHP files as your editor/IDE creates them, and make sure it does not include a BOM which most don't - For your HTML pages, using a Content-Type header or better a <meta charset> directive in the markup If any of those does not match the others then you'll have problems. Quote Link to comment Share on other sites More sharing options...
ETSoft Posted July 18, 2021 Author Share Posted July 18, 2021 Hi thank you when i insert the data with phpMyAdmin, it shows the correct characters, so i think the database is ready to accept this. Only when i 'upload' the data with the mentioned html page and php function it does not do the job. I've now tried in with the following between het <head> tags seperatly but without the correct result: <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> <meta charset="utf-8"/> Quote Link to comment Share on other sites More sharing options...
ETSoft Posted July 18, 2021 Author Share Posted July 18, 2021 (edited) This did the trick : <?php header('Content-Type: text/html; charset=utf-8'); if(isset($_POST['submit'])){ $DBCon = new mysqli("localhost", "tacssuite_yara", "D29XkTh4", "tacssuite_yara"); mysqli_set_charset($DBCon, "utf8mb4"); $result = $DBCon->query($_POST['query_input']); echo "<span style='color: green;'>Hochladen in Datenbank bereit!! </span>"; } ?> The 'mysqli_set_charset($DBcon , "utf8mb4")' cammand helped me out. Edited July 18, 2021 by ETSoft additional info Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.