I have the code below and I want to add greek characters in my DB table. The encoding of the database and table is "utf8_general_ci". The entries are shown like that: "Î’Ïαχιόλ". Is there anything wrong with my .php code?
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "products";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Escape user inputs for security
$itemname = mysqli_real_escape_string($conn, $_REQUEST['itemname']);
$descr = mysqli_real_escape_string($conn, $_REQUEST['description']);
$image = mysqli_real_escape_string($conn, $_REQUEST['image']);
$price = mysqli_real_escape_string($conn, $_REQUEST['price']);
// attempt insert query execution
$sql = "INSERT INTO items (itemname, descr, image, price) VALUES ('$itemname', '$descr', '$image', '$price')";
if(mysqli_query($conn, $sql)){
echo "Success.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
?>
No comments:
Post a Comment