Jquery submit form with utf-8

i need help with a form submit.

here is my code

<script type="text/javascript" src="js/jquery-1.7.2.js"></script>

    <script type="text/javascript">  
  $(document).ready(function(){  
    $("#form").submit(function(event) {  

        /* stop form from submitting normally */  
        event.preventDefault();   

        $.post( \'clase/app/add_meniu.php\', $("#form").serialize(),  
          function( data ) {  
              $("#status").append(data);  
          }  
        );  
      });  
  });  
</script>  

and here is the html

<form id="form" method="post" accept-charset="UTF-8" >
         <fieldset>
<p>
        <label>Denumire</label>
        <input class="text-input small-input" type="text" name="text"   maxlength="200" value="">
    </p>
<p>
        <label>Link</label>
        <input class="text-input small-input" type="text" name="link"  maxlength="200" value="">
    </p>

here is the add_meniu.php code

   require_once('../core/db.php');
$text=$_POST['text'];
    $link=$_POST['link'];
    $limba=$_POST['limba'];
echo'<div class="notification success png_bg">
                <a href="#" class="close"><img src="resources/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>
                <div>
                    Meniul '.$text.' a fost adaugat cu succes
                </div>
            </div>';

$query = "Insert into Meniu (Denumire,Link,ID_Limba)  VALUES ('".$text."','".$link."','".$limba."')";
$result = mysql_query($query)
or die("query failed: " . mysql_error());

The thing is that in database when i insert info's from the external file "add_meniu.php" it doesnt insert it with UTF-8. I have my page, form and mysql table utf-8 , can you pls give me a solution?

Upvotes: 0

Views: 2152

Answers (3)

Marcio Mazzucato
Marcio Mazzucato

Reputation: 9305

Firstly, it is strongly recommended that you check if your PHP file has the UTF-8 format without BOM, you can see this easily using Notepad++ and convert it if necessary.

Other points i recommend to check:

HTML

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

PHP

ini_set( 'default_charset', 'UTF-8' );
mb_internal_encoding('UTF-8');

MySQL

mysql_query("SET NAMES 'utf8'");

Upvotes: 1

A. Wolff
A. Wolff

Reputation: 74420

If you are speaking about data inserted in your mysql database, you have to set how mysql will display data.

Use the following query when just after setted your db connection in php file:

mysql_query("SET NAMES 'utf8'");

This as to be done on each connection as its relative to db session.

Upvotes: 0

wesside
wesside

Reputation: 5740

Likely, its your DB then.

mysql_query("SET NAMES utf8");

Upvotes: 0

Related Questions