我一直在試圖解決這個問題一段時間,我花了無數的時間在網絡上搜索它的解決方案。所以我想我會來找你們的,因爲我在這個問題上很有智慧。基本上我有一個CMS系統,我設計了一段時間後,我最近使用PDO等現代標準更新它,現在我似乎有一個問題在MySQL數據庫中插入&符號(&),一切都設置爲'UTF- 8',PDO連接,MySQL歸類,所有內容,但由於某些原因,當textarea的表單中有一個&符號時,數據將被髮送,但在達到&符號時會被截斷,就好像它正在解析它並且切斷它,因爲它認爲&符號是一個漏洞。向MySQL插入&符號的問題
這裏是我在PHP中插入代碼:
$fbl = $_POST['fblValue'];
$fbr = $_POST['fbrValue'];
$sbl = $_POST['sblValue'];
$sbr = $_POST['sbrValue'];
$tbl = $_POST['tblValue'];
$tbr = $_POST['tbrValue'];
$fblDisabled = $_POST['fblDisabled'];
$fbrDisabled = $_POST['fbrDisabled'];
$sblDisabled = $_POST['sblDisabled'];
$sbrDisabled = $_POST['sbrDisabled'];
$tblDisabled = $_POST['tblDisabled'];
$tbrDisabled = $_POST['tbrDisabled'];
$footer = $_POST['footerValue'];
$copyright = $_POST['copyrightValue'];
$statement = $conn->prepare("UPDATE pages SET FBL = :fbl,
FBLDisabled = :fblDisabled,
FBR = :fbr,
FBRDisabled = :fbrDisabled,
SBL = :sbl, SBLDisabled = :sblDisabled,
SBR = :sbr, SBRDisabled = :sbrDisabled,
TBL = :tbr, TBLDisabled = :tblDisabled,
TBR = :tbr, TBRDisabled = :tbrDisabled,
Footer = :footer,
Copyright = :copyright
WHERE ID = :pageToEdit");
$statement->bindParam(":fbl", $fbl);
$statement->bindParam(":fblDisabled", $fblDisabled);
$statement->bindParam(":fbr", $fbr);
$statement->bindParam(":fbrDisabled", $fbrDisabled);
$statement->bindParam(":sbl", $sbl);
$statement->bindParam(":sblDisabled", $sblDisabled);
$statement->bindParam(":sbr", $sbr);
$statement->bindParam(":sbrDisabled", $sbrDisabled);
$statement->bindParam(":tbl", $tbl);
$statement->bindParam(":tblDisabled", $tbDisabled);
$statement->bindParam(":tbr", $tbr);
$statement->bindParam(":tbrDisabled", $tbrDisabled);
$statement->bindParam(":footer", $footer);
$statement->bindParam(":copyright", $copyright);
$statement->bindParam(":pageToEdit", $pageToEdit);
$statement->execute();
}
也可能我補充一點,我使用Ajax來發送數據,有沒有一種可能性,即它的東西做的?
這裏是AJAX代碼:
<script type="text/javascript">
function savePage(str1, str2, str3, str4, str5, str6, str7, str8, str9, str10, str11, str12, str13, str14)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("post", "putEditedPage.php", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("fblValue=" + str1 + "&fbrValue=" + str2 + "&sblValue=" + str3 + "&sbrValue=" + str4 + "&tblValue=" + str5 + "&tbrValue=" + str6 + "&fblDisabled=" + str7 + "&fbrDisabled=" + str8 + "&sblDisabled=" + str9 + "&sbrDisabled=" + str10 + "&tblDisabled=" + str11 + "&tbrDisabled=" + str12 + "&footerValue=" + str13 + "©rightValue=" + str14);
document.getElementById('blackout').style.display="block";
document.getElementById('Alert').style.display="block";
document.getElementById('Alert').style.marginTop=((window.innerHeight/2)+((window.innerHeight/100) * 35))+"px";
setTimeout(function(){
document.getElementById('blackout').style.display='none';
document.getElementById('Alert').style.display='none';
}, 1250);
}
function insertTab(o, e)
{
var kC = e.keyCode ? e.keyCode : e.charCode ? e.charCode : e.which;
if (kC == 9 && !e.shiftKey && !e.ctrlKey && !e.altKey)
{
var oS = o.scrollTop;
if (o.setSelectionRange)
{
var sS = o.selectionStart;
var sE = o.selectionEnd;
o.value = o.value.substring(0, sS) + "\t" + o.value.substr(sE);
o.setSelectionRange(sS + 1, sS + 1);
o.focus();
}
else if (o.createTextRange)
{
document.selection.createRange().text = "\t";
e.returnValue = false;
}
o.scrollTop = oS;
if (e.preventDefault)
{
e.preventDefault();
}
return false;
}
return true;
}
</script>
在此先感謝球員,歡呼聲。
剛剛糾正了這個問題,對不起傢伙。 –