www.webdeveloper.com
Results 1 to 2 of 2

Thread: UTF-8 Character issues

  1. #1
    Join Date
    Oct 2007
    Posts
    151

    UTF-8 Character issues

    Hi,

    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.

    PHP Code:
    <?php
    include_once("classes/Database.php");

    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");
    while(!
    feof($file))
    {
        
    $line fgets($file);
        
        
    $db->query("insert into hotels(address2) values('$line')");
    }
    fclose($file);

    ?>
    Thanks

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,918
    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.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles