我有这个网站的html页面(.php文件),并且在某些时候我有这个PHP脚本(仔细看看输入的onclick属性,因为问题围绕那里):完整的PHP脚本位于帖子的底部。
<?php
require $_SERVER["DOCUMENT_ROOT"]."my-site/Database/db_connection.php";
/*Some code was here.*/
while($Student=$Result->fetch_row()){
echo "<input class='Content_Link' id='".$Student[0]."' type='button' value='".$Student[1]." ".$Student[2]."' onclick='redirecter('.''.')'/>";
}
/*normally a url would be passed into redirecter. To simplify the code during debugging,
I have removed the url*/
mysqli_free_result($Result);
$Conn->close();
/*a little more code*/
?>
按钮显示正确,但是...... 当按下按钮时,我得到一个意外的令牌},这是一个相当简单的错误,直到我将文本编辑器中的代码与浏览器开发人员工具中的代码进行比较。
此外,在彻底检查php脚本中的所有{}对以及脚本内所有必需/包含的文件(3次以上)之后,解决意外令牌。所有对都被计算并完成。没有找到额外的括号。
到目前为止,我已尝试过微软边缘的网站,google chrome和firefox。他们都使用onclick属性显示奇怪的东西:
文本编辑器 -
<input class='Content_Link' id='".$Student[0]."' type='button' value='".$Student[1]." ".$Student[2]."' onclick='redirecter('.''.')'/>
(将php值直接放在:)
<input class='Content_Link' id='2' type='button' value='Tyler Breau' onclick='redirecter('.''.')'/>
Chrome -
<input class="Content_Link" id="2" type="button" value="Tyler Breau" onclick="redirecter(" .''.')'>
Firefox -
<input id="2" class="Content_Link" value="Tyler Breau" onclick="redirecter(" .''.')'="" type="button"></input>
Microsoft Edge(最奇怪的是) -
<input class="Content_Link" id="2" onclick="redirecter(" type="button" .''.')'="" value="Tyler Breau" />
差异:
目前
onclick='redirecter('.''.')'/>
浏览器&#39;开发人员工具将此显示为以下常见差异:
onclick="redirector(" .''.')'>
第一首单曲:&#39;在括号中放置一个双引号后跟一个空格:&#34; 。此外,正在删除用于结束输入标记的正斜杠。 &#39; /&GT;成为&#39;&gt;
通过添加=&#34;&#34; Firefox变得更加时髦到redirecter结尾:
"redirecter(" .''.')'=""
通过放置type =&#34;按钮&#34;而Microsoft Edge更加时髦在redirecter括号旁边:
"redirecter(" type="button" .''.')'=""
我的问题......世界上到底发生了什么?你怎么开始调试这个......
我正在使用的程序/版本/等:
Sublime 3
Apache 2.4.17(全部来自http://www.wampserver.com/en/)
PHP 7
HTML5
完整的PHP脚本:
包含和必填代码包含在已注释的包含(开始)和&#39;结束包含&#39;或者&#39;结束要求&#39; (结束)。一个例子出现在php脚本的最开头。
<?php
//include $_SERVER["DOCUMENT_ROOT"]."my-site/General/get_user_type.php";
require $_SERVER["DOCUMENT_ROOT"]."my-site/Database/db_connection.php";//No brackets are present in file
if(!(isset($_SESSION))){
session_start();
}
$Result=mysqli_query($Conn, "SELECT Type FROM user_accounts WHERE ID=".$_SESSION["uid"]);
$Type=$Result->fetch_object()->Type;
mysqli_free_result($Result);
$Conn->close();
//End include
if($Type === "Admin"){
echo "<div class='Sub_Content' id='div_Student_List'>
<p class='Sub_Content_Title'> Student List </p>
<input class='Content_Link_Viewer' id='btn_Student_List' type='button' value='show' name='div_Students' onclick='displayContent(this.id, this.value)'/>
<p class='Content_Link_Describer'> - Students </p><br/>
<div class='Content_Link_Holder' id='div_Students'>";
//require $_SERVER["DOCUMENT_ROOT"]."my-site/Home_Page/student_list.php";
require $_SERVER["DOCUMENT_ROOT"]."my-site/Database/db_connection.php";//No brackets are present in this file
$Result=mysqli_query($Conn,"SELECT Class_Code FROM user_accounts WHERE ID=".$_SESSION["uid"]);
if($Result===false){
$Conn->close();
$Student_List="Oops! Failed to get Student List";
}else{
$Class_Code=$Result->fetch_object()->Class_Code;
mysqli_free_result($Result);
$Result=mysqli_query($Conn,"SELECT Student_ID, Student_First_Name, Student_Last_Name FROM student_list WHERE Class_Code='$Class_Code'");
if($Result===false){
$Conn->close();
$Student_List="Oops! Failed to get Student List";
}else{
while($Student=$Result->fetch_row()){
/*Problem button here*/ echo "<input class='Content_Link' id='".$Student[0]."' type='button' value='".$Student[1]." ".$Student[2]."' onclick='redirecter('.''.')'/>";
}
mysqli_free_result($Result);
$Conn->close();
}
}
//End Require
echo "</div>
</div>";
}
?>
答案 0 :(得分:0)
正如sTx在此评论中所建议的那样:characters being replaced/removed when running in browser?
在redirecter()中转义双引号修复了这种非常奇怪的行为。