I am trying to make an article poster that works perfectly until I put special characters in the html form (like ;,! etc.). I Googled it and found something about the table collation (which is utf8_unicode_ci by default).
I have <meta charset="utf-8"> into the header file and mysqli_set_charset($conn, 'utf8') after connection to the database. Also the form has accept-charset="utf-8" attribute.
Here is what happens after sending the form:
if(isset($_POST['sendForm']))
{
$articleTitle = $_POST['title'];
$articleText = $_POST['text'];
$name = $_SESSION['name'];
$currentDateMySQL = date("Y.m.d");
$sql = "INSERT INTO articles (title, text, owner, date_added) VALUES ('$articleTitle', '$articleText', '$name', '$currentDateMySQL')";
$result = mysqli_query($conn, $sql);
if($result === false)
{
$color = "red";
$infoText = "Could not insert your information into the database. Error number: <b>" . mysqli_errno($conn) . "</b>. :( Try again.";
}
else
{
$color = "green";
$infoText = "Succesfully writen the article into the database. :)";
}
}
Also the given error number is 1064. There is no error in the SQL code, it works perfectly without special characters.