(PHP)插入数据库时str_replace不工作

(PHP)插入数据库时str_replace不工作,php,string,str-replace,Php,String,Str Replace,我有个问题。我不擅长php,所以我请求帮助。我在数据库中创建了一个包含两行的表: 我还有一个简单的(可能不安全的)(插入数据)脚本: 连接: $db = new PDO('mysql:host=localhost;dbname=xxx;charset=utf8', 'xxx', 'xxx'); 发布数据 $renginioid = ($_POST['renginioid']); $renginioid = strtolower($_POST['renginioid']); $renginio

我有个问题。我不擅长php,所以我请求帮助。我在数据库中创建了一个包含两行的表:

我还有一个简单的(可能不安全的)(插入数据)脚本:

连接:

$db = new PDO('mysql:host=localhost;dbname=xxx;charset=utf8', 'xxx', 'xxx');
发布数据

$renginioid = ($_POST['renginioid']);
$renginioid = strtolower($_POST['renginioid']);
$renginioid = str_replace(" ", "-", $renginioid);
$renginioid = str_replace("ą", "a", $renginioid);
$renginioid = str_replace("č", "c", $renginioid);
$renginioid = str_replace("ę", "e", $renginioid);
/* etc */
插入

$stmt = $db->prepare("INSERT INTO renginiai(renginioid, pavadinimas, vadovai, programa, menesis, adresas, mda6) VALUES('$renginioid', '$pavadinimas', '$vadovai', '$programa', '$menesis', '$adresas', '$mda6')");
$stmt->execute();
问题:

$db = new PDO('mysql:host=localhost;dbname=xxx;charset=utf8', 'xxx', 'xxx');
我在$renginioid和$pavadinimas上使用相同的帖子。strtolower工作正常,而str_replace根本不工作

我需要将ą替换为a,ą替换为c…等等,但是这个脚本不起作用。(我需要将这些字母转换为英文字母)

其他问题:

$db = new PDO('mysql:host=localhost;dbname=xxx;charset=utf8', 'xxx', 'xxx');
这个脚本可以在所有行中插入英文字母,但如果我使用的是其他字母,则除了renginioid行之外,其他所有行都能很好地完成任务。那场争吵让我痛苦了好几个小时

renginioid行是主行

谢谢大家的帮助


抱歉,英语不好。

HTML
中要显示utf8特殊字符,请将其放入

要推送表中的行,请使用以下命令:

utf8_decode($variable);
更多信息,请点击此处:


使用此特殊的html字符表可以改进str_替换代码:

对于使用htmlspecialchars:)


几分钟前我就试过了,但数据库给了我“?-?-?”。顺便说一句,这不是你应该如何使用准备好的语句;
->execute()
用于发送变量,而
->prepare()
应该只有占位符。什么意思:“要在表中推送行,请使用这个”?在您的教程结束后,现在我得到了这样的信息:“ääääååå«å¾”。要插入到数据库中,请尝试使用以下列表替换:$renginioid=sträreplace(“ą”、“ą;”,$renginioid);如果没有utf8编码和utf8解码功能,请参阅:在数据库和脚本中使用我的语言,一切都可以。脚本将字母完美地插入所有行,但renginioid行除外。我不需要那一行的字母,我需要的是那一行的英文字母。我用输入的LT字母书写,而不是用破折号替换空格,并且我需要将LT字母转换为EN字母:/I感谢您的帮助,但它不起作用:/
   $renginioid = htmlspecialchars($_POST['renginioid'], ENT_QUOTES, 'utf-8');