I have been looking for an answer for a couple days, and thus far haven't found an answer...
I am building a website for a client, and am using a MySQL database to store data for a menu, and am using PHP mysqli prepared statements for working with the database. When I use a form to update or add rows, special characters are inserted wrong, accented "é" characters become é when submitted. Though, if I enter them in manually though phpMyAdmin, they show up just fine.
I have had a bit of luck by adding this after the $mysqli object, as recommended here
$mysqli -> set_charset( "utf8" );
This only seems to make it work with the update and insert commands, anything selected now shows the "tilda A copyright" in place of the accented e's, so it's basically the same problem, but reversed.
Here is some of my PHP that is affected:
$mysqli = new mysqli( "localhost", "user", "pass", "db" );
$mysqli -> set_charset( "utf8" );
if( $_GET['mode'] == "edit" && $_GET['drink'] && $_POST['e_name'] ) {
$update = "update `menu` set `name` = ?, `description` = ?, `small` = ?, `medium` = ?, `large` = ?, `flavors` = ?, `section` = ?, `order` = ? where `id` = ?;";
$id = $_GET['drink'];
$nName = $_POST['e_name'];
$nDesc = $_POST['e_desc'];
$nSml = $_POST['e_prc1'];
$nMed = $_POST['e_prc2'];
$nLrg = $_POST['e_prc3'];
if( $_POST['e_flav'] == "on" )
$nFlv = 1;
else
$nFlv = 0;
$nSect = $_POST['e_sect'];
$nOrd = $_POST['e_ordr'];
if( $changeIt = $mysqli -> prepare( $update ) ) {
$changeIt -> bind_param( 'ssdddiiii', $nName, $nDesc, $nSml, $nMed, $nLrg, $nFlv, $nSect, $nOrd, $id );
$changeIt -> execute();
}
header( "Location: http://stackoverflow.com/" );
exit;
}
$mysqli -> close();