使用表单方法更新mysql表(UTF8)

时间:2018-10-14 18:53:24

标签: php mysql

我正在尝试使用表单更新表查询UTF8。它以表格形式显示,但无法编辑。请让我知道查询的错误是什么?

<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
require_once("./includeadmin/membersite_config.php");
require_once("./includeadmin/membersite_config_editorial.php");
include("database1.php");
if(!$fgmembersite->CheckLogin())
{
$fgmembersite->RedirectToURL("index.php");
exit;
}


$idi = $_POST['id2'];
$sql = mysql_connect("localhost","username","password");

if (!$sql) {
die ('Could not connect!: ' . mysql_error());
}
mysql_select_db("nam33_articles", $sql);
mysql_query("UPDATE editorial SET date = '$_POST[date]', tag =         
'$_POST[tag]', title = '$_POST[title]', small = '$_POST[small]', image = 
'$_POST[image]', smallimage = '$_POST[smallimage]', english = 
'$_POST[english]', full = '$_POST[full]') WHERE id_user = '$idi'");
?>

1 个答案:

答案 0 :(得分:0)

更新查询参数并设置utf8。

mysql_query("set names 'utf8'",$sql);
$query = "UPDATE editorial SET date = '".$_POST['date']."', tag = '".$_POST['tag']."', title = '".utf8_encode($_POST['title'])."', small = '".utf8_encode($_POST['small'])."', image = '".$_POST['image']."', smallimage = '".$_POST['smallimage']."', english = '".$_POST['english']."', full = '".utf8_encode($_POST['full'])."' WHERE id_user = '$idi'";
mysql_query($query);