我有html表单和php脚本,用于在mysql表中插入一些值。 表字段设置为utf8_unicode_ci。 在插入克罗地亚字母(žšđčć)时,我收到错误字符串值不正确:'\ x9A \ xF0 \ xE8 ...等在第1行的列名称。我找到了一些帮助搜索谷歌,其中一个解决方案是将字段更改为ut8mb4但仍然有同样的问题。
我在XAMPP 1.8.3上运行mySQL 5.6.14,php 5.5.11
这是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: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $message, $headers) )
{
header('Location: finish.html');
}
?>
还有什么办法可以解决这个问题?
答案 0 :(得分:0)
当我必须处理特殊字符时,我总是会看几件事:
--------------------------------
| Names |Process_id | total|
--------------------------------
|construction 1001 1001 |
|engineering 1005 1005 |
|total 0 2006 |
----------------------------------
header("Content-Type: text/html;charset=utf-8");
helpfull link。所以我认为你的问题在于脚本和数据库之间的联系。