1

I have a problem to insert urdu news in mysql data_base using PHP.
HTML

<form method="post" action="">
<textarea name="content">Insert news article here.</textarea>
<input type="submit" value="Submit"/>

php

$content = $_POST['content']; $queryNews = "INSERT INTO yob_news (title, content, date) VALUES('$title','$content','$date')";
mysql_query($queryNews);

After insertion enter image description here Already add <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8"/> enter image description here

Adeel Gill
  • 353
  • 4
  • 19
  • 1
    Nice `SQL Injection` :D and `mysql_`! I would recommend you `PDO` or `mysqli_` – Rizier123 Nov 04 '14 at 23:05
  • Question is not about SQL injection @Rizier123 – Adeel Gill Nov 04 '14 at 23:07
  • Try `mysqli_set_charset($con,"utf8");` and also echo `$_POST['content'];` before you insert it and post what you get – Rizier123 Nov 04 '14 at 23:10
  • I already try `mysql_query ("set character_set_results='utf8'"); ` and `echo` the `POST` text is alright but in database same problem occur – Adeel Gill Nov 04 '14 at 23:12
  • 1
    Also try this: `mysql_query("SET NAMES 'utf8'");` or `ini_set("default_charset", "UTF-8");` or it could be this `header('Content-type: text/html; charset=UTF-8');` and as i said please post what you get if you echo `$_POST['content'];` – Rizier123 Nov 04 '14 at 23:17
  • Thank you @Rizier123 `mysql_query("SET NAMES 'utf8'");` work greatly. – Adeel Gill Nov 04 '14 at 23:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/64272/discussion-between-adeel-gill-and-rizier123). – Adeel Gill Nov 04 '14 at 23:25

1 Answers1

2

I think this should work for you:

mysql_query("SET NAMES 'utf8'");

otherwise you can try these ones out:

mysqli_set_charset($con,"utf8");
mysql_query ("set character_set_results='utf8'");
ini_set("default_charset", "UTF-8");
header('Content-type: text/html; charset=UTF-8');
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Rizier123
  • 58,877
  • 16
  • 101
  • 156