-2

So I use the following line of code to insert a chat message into my MySQL database:

$this->db->query("INSERT INTO group_messages (group_message_text,group_message_group_id,group_message_user_id) VALUES ('$message','$group_id','$user_id');");

This works great until the users tries to use characters like ' or emoji's. How do I handle that properly?

Rutger Huijsmans
  • 2,330
  • 2
  • 30
  • 67

2 Answers2

0

To store emoji's in your database you have to store it in utf8mb4. See this answer.

You should also escape your text bevor storing it into the database. See this answer as well.

Community
  • 1
  • 1
Leon Husmann
  • 664
  • 1
  • 6
  • 25
0

Might be the Syntax error:

Please try using 
$this->db->query("INSERT INTO group_messages (group_message_text,group_message_group_id,group_message_user_id) VALUES ('".$message."','".$group_id."','".$user_id."');");

Hope this will help :)

Binit Ghetiya
  • 1,919
  • 2
  • 21
  • 31