我有一页来编辑数据。在这种情况下,我将显示该页面以编辑法语数据。问题是,当我以法语粘贴文本并单击以进行编辑和更新时,它假定为mysql_error。这只是发生在法语和英语之间,我可以用葡萄牙语来做到这一点。我只使用这种树语言。
我已经尝试了一些方法,但是没有任何反应...
评论的是我尝试过的。
当我按下按钮时,将发生以下情况:“ Ocorreu um erro,tente de novo!您的SQL语法有误;请查看与您的MariaDB服务器版本相对应的手册,以获取在'ontforcéà附近使用的正确语法。第1行的travailler comme apprentiàl'usine d'orfèvreriede son'
<?php
session_start();
$cookie_name = "loggedin";
if (isset($_COOKIE[$cookie_name])){
$cookie_value = $_COOKIE[$cookie_name];
}else {
echo "O seu tempo expirou, inicie sessão novamente!";
header("Refresh:2; url=/estagio/admin/login.php");
}
ini_set ('default_charset', 'UTF-8');
mysql_set_charset('utf8');
//header ("content-type: text/html; charset=utf-8");
//mysql_query("SET NAMES 'utf8'");
//mysql_query("SET character_set_connection=utf8");
//mysql_query("SET character_set_client=utf8");
//mysql_query("SET character_set_results=utf8");
mysql_connect ("localhost", "root", "") or die ("Erro na conexão " .mysql_error());
mysql_select_db ("casadoadro") or die ("Erro na seleção da base de dados " .mysql_error());
$editid = $_GET['eid'];
if (!isset($_GET['eid']) || empty($_GET['eid'])){
header ("location: admin_biografia.php");
}
$editquery = mysql_query("select * from tb_biografia where id='{$editid}'") or die (mysql_error());
$editdata = mysql_fetch_row($editquery);
if ($_POST)
{
$id = htmlspecialchars ($_POST['id']);
$title_fr = htmlspecialchars ($_POST['title_fr']);
$subtitle_fr = htmlspecialchars ($_POST['subtitle_fr']);
$text_fr = htmlspecialchars ($_POST['text_fr']);
$q = mysql_query ("UPDATE tb_biografia SET title_fr='{$title_fr}', subtitle_fr='{$subtitle_fr}', text_fr='{$text_fr}' WHERE id='{$id}'") or die ("Ocorreu um erro, tente de novo! " .mysql_error());
if($q){
echo "<script>alert ('Editado com sucesso'); window.location='admin_biografia.php'</script>";
}
}
?>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" type="text/css" href="/estagio/css/styles.css">
<title>Casa do adro</title>
</head>
<body>
<div class="col-2"></div>
<div class="col-8">
<div class="col-12 w3-card-4 nopadding">
<form method="post" class="w3-container w3margin" enctype="multipart/form-data">
<input type="hidden" name="size" value="10000000" />
<div class="w3-row mtb">
<div class="w3-col" style="width:150px">ID</div>
<div class="w3-rest">
<?php echo $editdata[0]; ?>
<input class="w3-input w3-border" type="hidden" name="id" value="<?php echo $editdata[0]; ?>">
</div>
</div>
<div class="w3-row mtb">
<div class="w3-col" style="width:150px">Título FR</div>
<div class="w3-rest">
<input class="w3-input w3-border" type="text" name="title_fr" value="<?php echo $editdata[2]; ?>">
</div>
</div>
<div class="w3-row mtb">
<div class="w3-col" style="width:150px">Legenda FR</div>
<div class="w3-rest">
<input class="w3-input w3-border" type="text" name="subtitle_fr" value="<?php echo $editdata[6]; ?>">
</div>
</div>
<div class="w3-row mtb">
<div class="w3-col" style="width:150px">Texto FR</div>
<div class="w3-rest">
<div class="w3-rest">
<textarea class="w3-input w3-border" rows="1" type="text" name="text_fr"><?php echo $editdata[9]; ?></textarea>
</div>
</div>
</div>
<button class="btnfbform w3-block mtb w3-ripple w3-input w3-border" type="submit" name="upload"> Editar texto</button>
</form>
</div>
</div>
<div class="col-2"></div>
</body>
</html>
最佳答案
以此替换您的代码。希望能帮助到你。谢谢。使用mysql_real_escape_string来转义特殊字符,并在查询php变量时删除{}。
if ($_POST)
{
$id = $_POST['id'];
$title_fr = mysql_real_escape_string($_POST['title_fr']);
$subtitle_fr = mysql_real_escape_string($_POST['subtitle_fr']);
$text_fr = mysql_real_escape_string($_POST['text_fr']);
$q = mysql_query ("UPDATE tb_biografia SET title_fr='$title_fr', subtitle_fr='$subtitle_fr', text_fr='$text_fr' WHERE id='$id}'") or die ("Ocorreu um erro, tente de novo! " .mysql_error());
if($q){
echo "<script>alert ('Editado com sucesso'); window.location='admin_biografia.php'</script>";
}
}
关于javascript - 尝试将法语/英语中的文本更新为mysql db时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44904497/