MySQL Forums
Forum List  »  PHP

PHP cannot insert non-English characters into mySQL table!
Posted by: Arthur Chan
Date: October 21, 2018 10:08AM

How do I insert non-English characters into mySQL using PHP?

What I can do successfully:
All mySQL rows are utf8mb4 encoded. In mySQL and using my sproc instead of PHP, I can insert parametric values in Chinese, Greek, German etc successfully.
Likewise, if I use Java HTTPS connection to execute the PHP, as long as the values are in English, the inserts and updates are successful. The HTTPS connection to cloud mySQL is always successful.

This is the problem:
But if I use PHP, the inserts result in a mess. After insert, the row value looks a bit like this mess

I am using _POST for insert.

Here is the PHP script:
$con = mysqli_connect("localhost", "username", "pwd", "instance");
if (mysqli_connect_errno($con)) {
   echo "Failed to connect to MySQL: ".mysqli_connect_error();

$coyName= $_POST['cName'];

$result = "INSERT INTO Company(Name) VALUES ('$cName')";
if(! mysqli_query($con, $result) ) {
    die('PHP cannot insert data! ' . mysqli_error());  
   } else {
  'New company $cName inserted successfully<br/>\n';

Options: ReplyQuote

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.