i'm facing an issue with inserting hebrew data from my php web page into mysql database. my collation for the table is utf8_general_ci. this is the php script
<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);
}
?>
when i try to insert hebrew data into my database with INSERT DATA directly from the mysql command line, it works fine.
Thank you!.
Try changing this:
mysqli_query("SET NAMES 'utf-8'");
mysql_set_charset('utf-8',$conn);
Sometimes one or the other works.
Change your form to this:
<form action="addask.php" action="post" accept-charset="UTF-8">
You'll also need to know if your database is using the format utf-8 or uft8. To find out, insert some Hebrew into your database, and try extracting it with both.
Also, you don't need both the UTF-8 meta and header. I have read having the meta slows down web browsers and the best solution is to set as UTF-8 in .htaccess
http://www.w3.org/International/questions/qa-htaccess-charset.en
But I can't vouch for that.