2015-06-19 21 views
-1

我有用於在mysql表中插入一些值的html表單和php腳本。 表字段被設置爲utf8_unicode_ci。 雖然插入克羅地亞字母(žšđčć)我得到錯誤不正確的字符串值:'\ x9A \ xF0 \ xE8 ...等行列1名稱。我發現一些幫助搜索谷歌和解決方案之一是將字段更改爲ut8mb4但仍然有同樣的問題。Croatina字符的字符串值不正確

我在XAMPP運行MySQL 5.6.14,PHP 5.5.11 1.8.3

這是HTML文件:

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



<form name="Prijava" method="post" action="insert.php"> 
<fieldset> 
<legend>Personal information:</legend> 
Ime:<br> 
<input type="text" name="_ime" maxlength="50"> 
<br> 
Prezime:<br> 
<input type="text" name="_prezime" maxlength="50"> 
<br> 
Spol:<br> 
<input type="radio" name="_spol" value="M" checked>M 
<br> 
<input type="radio" name="_spol" value="Z">Ž 
<br> 
Godište:<br> 
<input type="text" name="_godiste" maxlength="4"<br> 
<br>E-mail adresa:<br> 
<input type="text" name="_emailadresa" maxlength="50"> 
<br> 
Grad/mjesto:<br> 
<input type="text" name="_gradmjesto" maxlength="50"> 
<br> 
Tip:<br> 
<input type="radio" name="_tip" value="Klub" checked>Klub 
<br> 
<input type="radio" name="_tip" value="Udruzenje">Udruženje 
<br> 
<input type="radio" name="_tip" value="Solo">Solo 
<br> 
<br> 
<p><input onchange="this.setCustomValidity(validity.valueMissing ? 'Molimo Vas potvrdite da prihvaćate uvijete!' : '');" id="field_terms" type="checkbox" required name="terms"> Prihvaćam <u>uvijete</u></p> 
<input type="submit" value="Submit"> 
</fieldset> 

<a href="select.php">Pregled popisa prijavljenih natjecatelja</a> 
</form> 

</body> 
</head> 
</html> 

,這是php:

<?php 

include 'config.php'; 

header("Content-Type: text/html;charset=utf-8"); 

if (!isset($_POST['_ime']) || 
!isset($_POST['_prezime']) || 
!isset($_POST['_spol']) || 
!isset($_POST['_godiste']) || 
!isset($_POST['_emailadresa']) || 
!isset($_POST['_gradmjesto']) || 
!isset($_POST['_tip'])) 
{ 
    died ("Nisu popunjena svi podaci!"); 
} else 
{ 
$ime = $_POST['_ime']; 
$prezime = $_POST['_prezime']; 
$spol = $_POST['_spol']; 
$godiste = $_POST['_godiste']; 
$email = $_POST['_emailadresa']; 
$grad = $_POST['_gradmjesto']; 
$tip = $_POST['_tip']; 


$sql_insert = "INSERT INTO prijave (IDUnos, Ime, Prezime, Spol, Godiste, Email, Grad, Tip) VALUES (null, '$ime', '$prezime', '$spol', '$godiste', '$email', '$grad', '$tip');"; 

mysql_query($sql_insert) or die(mysql_error()); 
mysql_close($con); 

} 


// slanje poruke 

$to  = $email; 
$subject = 'Prijava na utrku'; 
$message = 'Ovdje ide poruka'; 
$headers = 'From: [email protected]' . "\r\n" . 
    'Reply-To: [email protected]' . "\r\n" . 
    'X-Mailer: PHP/' . phpversion(); 

if (mail($to, $subject, $message, $headers)) 
{ 
header('Location: finish.html'); 
} 


?> 

還有什麼辦法來解決這個問題?

+0

你確定它在utf8_unicode_ci上嗎?這裏工作得很好。我的mySQL是早期的版本。 – PHPhil

+0

是的。我剛剛檢查過。不知道該怎麼辦......表格字段接受特殊字符,但插入和顯示數據不顯示正確。 – Josef

回答

0

當我不得不面對特殊字符我總是看有兩件事情:

  1. 數據庫,表和字段字符集都被設置爲utf8_unicode_ci。
  2. 使用標頭修改HTTP標頭。 header("Content-Type: text/html;charset=utf-8");
  3. 指定從/向數據庫服務器發送數據時要使用的缺省字符集:mysqli_set_charset($connect, 'utf8'); helpfull link

所以我認爲你的問題是在腳本和數據庫之間的連接。