-1
I’m having trouble finding a solution to my problem. Briefly:
I send data to a table, using a php file that does querry, and an ajax call that sends all the values I need to the php file. When it is inserted in the table the accents of the words are all crazy. If I add entries to the table using phpmyadmin this error does not happen. How can I resolve?
Call AJAX:
pageurl = 'http://estradasegura.pt/exames/testesDB.php'; //para consultar mais opcoes possiveis numa chamada ajax //http://api.jquery.com/jQuery.ajax/ $.ajax({ //url da pagina url: pageurl, //parametros a passar data: dadosajax, //tipo: POST ou GET type: 'POST', //cache cache: false,
PHP file connecting to Mysql:
ini_set('display_errors', true); error_reporting(E_ALL); $dbname = 'nomedabasededados'; $username = 'meuusername'; $password = 'ahahahaha'; $servername = 'localhost'; $pergunta = $_POST['pergunta']; $resA = $_POST['resA']; $resB = $_POST['resB']; $resC = $_POST['resC']; $resD = $_POST['resD']; $resE = $_POST['resE']; $acertaram = intval($_POST['acertaram']); $falharam = intval($_POST['falharam']); $dificuldade = intval($_POST['dificuldade']); $resposta = intval($_POST['resposta']); $imgSrc = $_POST['imgSrc']; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = " INSERT INTO perguntas ( pergunta, resA, resB, resC, resD, resE, acertaram, falharam, dificuldade, resposta, imgSrc ) VALUES ( "; $sql .= "'$pergunta', '$resA', '$resB', '$resC', '$resD', '$resE', '$acertaram', '$falharam', '$dificuldade', '$resposta', '$imgSrc' )" ; $result = mysqli_query($conn, $sql); $conn->close(); ?>
The table is in UTF8 ?
– Alex
is in utf8_general_ci
– ihavenokia
It may be three things, I don’t touch mysqli (PDO use), but my DSN in PDO is utf8. Or it may be your header('content-type text/html charset=utf-8'). It may also be the file, if your file is being saved as utf8
– Alex
header('content-type text/html charset=utf-8') I used this before asking, but as it did not change anything I took from php. As for the file...I don’t know what it is because I made my first code in php and mysql yesterday and only had a few hours to figure out how to use values from/for the database
– ihavenokia
You use a Notepad++ ?
– Alex
yes, to edit PHP I use Notepad++, to edit html and that I use Brackets (Filezilla opens php with Notepad++ by default and was not there to change)
– ihavenokia