Jump to content

Uploading data to a MySql database using a form, wrong character set!


Recommended Posts

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&#252ge 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 by ETSoft

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.

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"/>

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 by ETSoft
additional info
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.