0

I have some value in other language and i want to use utf-8 for this value.for now i use this code for store variable in database.

<?php
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
$stmt=$mysqli->prepare("INSERT INTO user (fname , lname) VALUES (? , ? ) ");
$stmt->bind_param("ss",$fname,$lname);
$stmt->execute();
?>

I set collation for fname and lname column to utf-8.but i do not know how to modify database connection for insert variable as utf-8.I set collation of user table as utf-8.

4
  • have you put utf8 headers in your php file? Commented Mar 6, 2014 at 7:43
  • Have you tried what I posted ? Commented Mar 6, 2014 at 7:47
  • @adib16 header('Content-Type: text/html; charset=utf-8'); on top of your file Commented Mar 6, 2014 at 7:50
  • @cryptivous yes thank you for that.but i think i must try both of your answer and the above comment.otherwise i must put uft8 header in php file and $mysqli->set_charset("utf8") . Commented Mar 6, 2014 at 7:51

1 Answer 1

1

Try:

header("Content-Type: text/html; charset=utf-8"); // at the top of the file

$mysqli->set_charset("utf8"); // before the query

Set Charset, Header

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.