I'm having trouble finding a solution to my problem. Briefly:
I send data to a table, using a php file that does the 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 occur. How can I solve?
-
AJAX call:
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 linking 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(); ?>