0

Update: SOLVED

I just inserted charset=utfmb4 in my connection string and it worked.

$pdo = new PDO("mysql:host=localhost;dbname=db_name;charset=utf8mb4", "db_user", "db_pass") 

phew!


Original Question:

I'm building a contextual reference word bank related to my work field. I have a form with three text fields, using it I keep record of certain English words and phrases and their contextual meaning in my native Odia language.

Input form 1."Context"

Input form 2."English Word"

Input form 3. "Oriya Word"

In the live server the Odia words (say, ସହର) gets inserted as ସହର

The character encoding/collation is set to "utf8mb4_general_ci" (same as my localhost, where the texts get inserted/displayed as intended)

I tried adding the line

<form action="insert.php" method="post" accept-charset="utf-8"> 

but it didn't help.

What's wrong?

insert.php

<?php /* Attempt MySQL server connection.*/ try{ $pdo = new PDO("mysql:host=localhost;dbname=my_db", "user_name", "passss"); // Set the PDO error mode to exception $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e){ die("ERROR: Could not connect. " . $e->getMessage()); } // Attempt insert query execution try{ // Create prepared statement $sql = "INSERT INTO my_glossary (Domain, Keyword, Oriya_Meaning) VALUES (:Domain, :Keyword, :Oriya_Meaning)"; $stmt = $pdo->prepare($sql); // Bind parameters to statement $stmt->bindParam(':Domain', $_REQUEST['Domain']); $stmt->bindParam(':Keyword', $_REQUEST['Keyword']); $stmt->bindParam(':Oriya_Meaning', $_REQUEST['Oriya_Meaning']); // Execute the prepared statement $stmt->execute(); echo "Records inserted successfully."; } catch(PDOException $e){ die("ERROR: Could not able to execute $sql. " . $e->getMessage()); } // Close connection unset($pdo); ?> <html> <p><a href="backend.php">Add another</a><p> 

The "Oriya_Meaning" field value is supposed to be in Odia script.

The rows highlighed in green were imported from localhost db. Other rows were inserted via live webform.

show create table my_glossary; OUTPUT

 CREATE TABLE `my_glossary` ( `Domain` varchar(255) DEFAULT NULL, `Keyword` varchar(2000) DEFAULT NULL, `Oriya_Meaning` varchar(2000) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci 
12
  • What does show create table my_glossary; tell you? And how are you testing how the data gets saved to the DB? Are you sure it's not just a display problem when retrieving the data? Commented Oct 31, 2023 at 15:08
  • Using phpMyAdmin or whatever tool you use to look at your database, run the query show create table my_glossary; and show us the output by EDITING the output into your question Commented Oct 31, 2023 at 17:08
  • Hi @RiggsFolly, I have added the screenshot after running the query; please be patient, I can't figure out what/where is the output of that query. Commented Oct 31, 2023 at 17:29
  • Please Never post images of or off site links to Code/Data/Error Messages. That query should show us the schema for that table, your images looses most of that Commented Oct 31, 2023 at 17:33
  • Output is in the create table cell, expand it and you should see more text Commented Oct 31, 2023 at 17:45

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.