SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Threaded View

  1. #1
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ajax data to mysql problem

    Hello
    I have a problem with character encoding while saving data from php/ajax to mysql. I'm using the prototype framework

    I set up a test application like this:

    PHP Code:
    <?php
    header
    ('Content-Type: text/html; charset=UTF-8'); 
    if(
    $_GET['do']){
     
     
    // insert value in database
     
    $conn mysql_connect("localhost""root""");
     
    $db mysql_select_db("test");
     
    $q mysql_query("INSERT INTO testtabel (value) VALUES ('".$_GET['print']."')");
     
     
    // print value
     
    echo $_GET['print'];
     exit;
    }
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="js/prototype.js"></script>
    </head>
    <body>
    <div id="result" style="border: 1px solid red;padding:5px">&nbsp;</div>
    <input type="text" id="txt"> <input type="button" value="Test" onclick="do_it()">
    <script type="text/javascript">
    <!--
    function do_it(){
     new Ajax.Updater('result', 'ajaxtest.php?do=nu',   {
     parameters: {print: $('txt').value},
     method: 'get'});
    }
    //-->
    </script>
    </body>
    </html>
    The returned Ajax value displays properly in any browser (ss1.gif), but when I look up the saved value in my database, I only see strange characters (ss2.gif).
    The field in my database is value varchar(50) utf8_unicode_ci.

    What to do?
    Attached Images Attached Images


Bookmarks

Posting Permissions

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