php echo showing question marks instead of arabic letters [duplicate] - php

This question already has answers here:
How do I send emails with Arabic content via PHP's mail function?
(4 answers)
UTF-8 all the way through
(13 answers)
Closed 5 years ago.
I use PHP (echo) to add user session data to the HTML page and it worked fine on one server but when I moved to another one it shows Arabic data in question marks like this (???). how to fix this?
NOTE 1: Arabic data added in the html page using HTML or JAVASCRIPT or AJAX call from database is showing correctly. it only shows question marks when using PHP echo command.
update: the first duplicate is about setting up a server but I'm using a shared webhosting. the second one is about sending email and changing the header didn't work for me.
UPDATE: looks like it was a problem while restoring the database to the new server. new entered data is showing correctly while old ones are messed up!

Related

php and mysql accent issues [duplicate]

This question already has answers here:
How to make MySQL handle UTF-8 properly
(15 answers)
UTF-8 all the way through
(13 answers)
Closed 5 years ago.
I'm new to php, i made a php user interface with input fields that formulates, prints and execute a query showing the database reply or error.
It usually works fine but when i make a query with accented fields like in
"INSERT INTO `Nave` (`Targa`, `Nazionalità`, `Nome`) VALUES('0', 'italia', 'nave0');"
php successfully creates the query, prints and executes it without any further modifications but it fails saying "Unknown column 'Nazionalità' in 'field list'"
but if i copy/paste the same exact query printed by php into phpmyadmin it works (so obiouvsly the column 'Nazionalità' does exist) what is happening?
Notice that if the php generated query has no fields with accent it works even in php.
Notice also that individually neither my php nor mysql have any issues dealing with accent. so it's NOT a duplicate of How to make MySQL handle UTF-8 properly because that's a mysql individual issues, my database works fine.
EDIT: All the answers so far explained how to fix the database, but the database does works fine!
I do not know how to make it understand that, read more about the question guys...
But the second duplicate suggestion was quite right and there i found my solution which I copy here for convenience of those who will visit this page having the same problem: "$mysqli->set_charset('put here the same charset used in your db');" OR "mysqli_set_charset($link, 'charset');"
Thank for your help.
change your character set of database to UTF-8 by following MySQL query
ALTER TABLE Nave CONVERT TO CHARACTER SET utf8;

UTF-8 Encoding of Pound Sign PHP [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 6 years ago.
I'm creating a messaging system with PHP and MySQL but am having problems when certain characters are entered. Particularly the Pound sign (£).
The form where users write their message is POSTed to a PHP script with the following functions:
$message = htmlspecialchars($message, ENT_QUOTES);
$message = utf8_encode($message);
Then $message is INSERTed into a Database where it is stored in a Text Column.
However, when inputing a Pound sign no data appears in the database at all on my live server, but on my localhost (using MAMP) £ appears in the database.
Anybody know whats going on? And is there a way to encode £ as £, I feel like that might solve my issue.
If your database encoding is not UTF-8, or if the application does not retrieve data from the database as UTF-8, data stored in the database will not render correctly.Check your db encoding please and if this is not the problem put this to your php page
header('Content-Type: text/html; charset=utf-8');

MYSQL texts looking weird [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 7 years ago.
I am making an android application that sends some TEXT to server and other people can see those Text but the problem is here when I send the TEXT it looks like this (سلام به همه) in the MYSQL table inside the server and it shows the text like this (???????????) (By the way I am writing the text in Persian) to the people who get the text and also when I add some records manually inside the database it also shows like question marks on the PHONE.
I tried puting database and tables Collation to utf8_general_ci and utf8_persian_ci but it did not work.
How do you send the data to the server, is it via a PHP Service? If so, I once had a problem with Cyrillic and setting the connection itself to UTF8 helped.
Here's the statement if you are using mysqli but I think there's an alternative for PDO as well.
mysqli_set_charset($con,"utf8");

Imported sql data with special characters shows correctly in phpMyAdmin but not in web [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 7 years ago.
I exported some tables in my mySQL database on my own server (localhost) to a web host using phpMyAdmin. The tables contain swedish special characters, and the CHARSET is set to latin1_swedish_ci. When imported, the characters look correctly in phpMyAdmin of the web host server, but when they are fetched and displayed on the web, there is a question mark (inside a diamond) instead of each special character.
If I update the data by fething the data into a form and then manually replace the question marks with the special characters and submit (thus updating the table), then the updated data shows correctly in the web when fetched.
But if I do the same thing but using the same update form on my own server where the fetched data displays correctly both in phpMyAdmin and web/localhost and setting the post attribute to the insert page on the web server, then that data does not display correctly (on the web).
I.e. this is the opposite problem of that explained in this post.
What might be wrong?
EDIT: As to the suggestion that using "UTF-8 all the way through" might solve the problem: My question more concerns how I might understand why a problem like this can occur. If the data looks ok in phpMyAdmin, does that mean that the problem lies simply in the fetching? Or might there still be something wrong with the data?
You need to ensure the character set is the same across your connection to the database and the web page it is displayed on.
You are best to use UTF-8 all the way.
On your web page you will need something like this:
So the browser knows what to display.

When i inserted string "Jack - Jill" in mysql db it saved as "hello – world" [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Insert into a table which has a dash in the name
(4 answers)
Closed 8 years ago.
While inserting data "Jack - Jill" in mysql db, it saving as "Jack †Jill“, my problem is when i tried to display the string in page its showing like "Jack �€� Jill", i am just botherd to display the string properly like "Jack - Jill", i tried have proper charactersets but not much of luck.
make sure you specify the charset used by your page to the database (and all its tables), and the other way around. i.e.:
Give your page a metatag and the script witing to the database a line that either validates that the charset is UTF-8 (example charset), or that it converts the chaarset to UTF-8
and give your database the same property, that it saves and reads data as UTF-8 (i use PHPMyAdmin, if you use such GUI tools too, its just a checkbox away).
hope i pointed you into the right direction

Categories