UTF-8 Character issues
I'm trying to read a file with japanese characters and then insert them into the database. I'm currently getting an error in the mysql syntax being caused by the characters. Can anybody help me with this issue in guiding me in the right direction of storing utf8 characters.
header("Content-Type: text/plain; charset=UTF-8"); // output as text file
header("Content-Type: text/html; charset=UTF-8");
$file = fopen("address2.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
$db->query("SET NAMES utf8");
$line = fgets($file);
$db->query("insert into hotels(address2) values('$line')");
May just be that you are not escaping the input and are encountering a SQL injection error. Not sure which database extension you're using, but if it supports prepared statements with bound parameters, I'd suggest using that; if not, then use the applicable escaping function for that DB extension.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)