gpt4 book ai didi

php - 将希伯来语数据插入 mysql php

转载 作者:行者123 更新时间:2023-11-29 13:24:36 25 4
gpt4 key购买 nike

我在将 php 网页中的希伯来语数据插入 mysql 数据库时遇到问题。我的表排序规则是 utf8_general_ci。这是 php 脚本

<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<body style="background-color:#990000;">
<h5 align="center" style="font-family:tahoma;color:white;font-size:45px;"> Fill A Question! </h5>
<form align="center" method="post" action="addask.php">
Course Number: <input type="text" name="CourseNum"><br>
Ask: <input align="20px" type="text" name="ask"><br>
<input type="submit" value="Ask">
<?php
header('Content-Type: text/html; charset=utf-8');
session_start();
$UserID = $_SESSION['UserID'];
$password = $_SESSION['password'];
if ((isset($_POST['CourseNum'])) && (isset($_POST['ask'])))
{
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$db = 'jonatandb';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $db);
if (!$conn)
{
die ('Could not connect: ' . mysql_error());
}
mysqli_query("SET NAMES 'utf8'");
$sql = "INSERT INTO Asks (UserID,Course_Num,Ask) VALUES ('$UserID','$_POST[CourseNum]','$_POST[ask]')";
mysqli_query($conn,$sql);
mysql_set_charset('utf8',$conn);
mysqli_close($conn);
}
?>

当我尝试直接从 mysql 命令行使用 INSERT DATA 将希伯来语数据插入我的数据库时,它工作正常。

谢谢!

<小时/>

最佳答案

尝试更改此设置:

mysqli_query("SET NAMES 'utf-8'");
mysql_set_charset('utf-8',$conn);

有时其中之一有效。

编辑

将您的表单更改为:

<form action="addask.php" action="post" accept-charset="UTF-8">

您还需要知道您的数据库使用的是 utf-8 还是 uft8 格式。要找到答案,请在数据库中插入一些希伯来语,然后尝试用两者提取它。

此外,您不需要同时使用 UTF-8 元和 header 。我读过元数据会减慢网络浏览器的速度,最好的解决方案是在 .htaccess 中设置为 UTF-8

http://www.w3.org/International/questions/qa-htaccess-charset.en

但我不能保证这一点。

关于php - 将希伯来语数据插入 mysql php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20317328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com