html未执行后的PHP块
我在html(.php)文档的正文部分有两块代码。我的标题前的代码块将执行,但标题后的代码块不会执行。我试过html未执行后的PHP块,php,html,Php,Html,我在html(.php)文档的正文部分有两块代码。我的标题前的代码块将执行,但标题后的代码块不会执行。我试过phpinfo()在第一个块中,它运行正常。在第二个街区试试看,结果没有。我不知道为什么会这样。如果有人有什么建议,我洗耳恭听 我目前正在windows计算机上运行xampp <body> <?php if (isset($_SESSION['ProfileID'])){ echo "<div style='text-align: right'>"
phpinfo()代码>在第一个块中,它运行正常。在第二个街区试试看,结果没有。我不知道为什么会这样。如果有人有什么建议,我洗耳恭听
我目前正在windows计算机上运行xampp
<body>
<?php
if (isset($_SESSION['ProfileID'])){
echo "<div style='text-align: right'>"
. "<a href='CZSN_Login.php'>Log "
. "Out</a></div>\n";
}
//here phpinfo() executes
?>
<h1>Chinese Zodiac Social Network</h1>
<?php
require_once("Includes/inc_ChineseZodiacDB.php");
//here phpinfo() will not execute
if (isset($_SESSION['ProfileID'])){
echo "<h2>Member Pages</h2>\n";
echo"<p>Below is a list of the members of the Chinese Zodiac Social"
. "Network. Click on a member's name to view that member's detailed information"
. "You may also choose to <a href='CZSN_MyProfile.php'>update your profile</a>.</p>\n";
$SQLQuery="select first_name, last_name, user_name "
. "from zodiac_profiles order by "
. "last_name, first name, user_name;";
$result=$DBConnect->query($SQLQuery);
if ($result===false){
echo $ErrorMsgs[];
}
else{
//This should never happen, but we can check anyway.
if ($result->num_rows==0){
echo "<p>There are no members to show.</p>\n";
}
尝试在require_中搜索一次(“Includes/inc_chinesesezodiacdb.php”)可以触发die()或exit() 我猜您会收到“已发送错误标题”,因为标题是《中国生肖社交网络》
。要使phpinfo()
工作,应该还没有任何输出。您正在关闭inc\u chinesesezodiacdb
文件中的php标记(即,您在该文件末尾有?>
)
当您的第一个文件读入inc_ChineseZodiacDB文件并看到?>
时,它会将其解释为php代码部分的结尾,而之后的所有其他代码都需要一次(“Includes/inc_ChineseZodiacDB.php”)代码>被忽略并作为常规html读取
删除该行,您的问题应该得到解决:
<?php
$ErrorMsgs = array();
$DBConnect = @new msqli("localhost", "root", "password", "chinese_zodiac");
if ($DBConnect->connect_error)
$ErrorMsgs[] = "The database server is not available."
. "Connect Error is "
. $mysqli->connect_errno
. " " . $mysqli->connect_error . ".";
我解决了最终的问题。在include文件中,它读取:
<?php
$ErrorMsgs = array();
$DBConnect = @new msqli("localhost", "root", "password", "chinese_zodiac");
if ($DBConnect->connect_error)
$ErrorMsgs[] = "The database server is not available."
. "Connect Error is "
. $mysqli->connect_errno
. " " . $mysqli->connect_error . ".";
?>
应改为:
<?php
$ErrorMsgs = array();
$DBConnect = @new mysqli("localhost", "root", "password", "chinese_zodiac");
if ($DBConnect->connect_error)
$ErrorMsgs[] = "The database server is not available."
. "Connect Error is "
. $mysqli->connect_errno
. " " . $mysqli->connect_error . ".";
?>
注意,我调用的是msqli
,而不是mysqli
。一个简单的输入错误…我仍然不明白为什么调用未定义函数时没有抛出错误消息。我添加了错误报告(E_ALL)代码>和ini\u集('display\u errors',1)代码>也显示在文件的顶部,但仍然没有抛出错误。不管是哪种方式,它现在都起作用了。谢谢大家的帮助 你有什么错误吗?要启用php错误报告,请在代码顶部添加错误报告(E_ALL)和初始化集(“显示错误”),然后运行文件。现在,你看到什么错误了吗?不,我没有看到任何错误。输出只是两个代码块之间的h1。您已经说过第二个块未执行,如果您只得到标记,那么第一个块也不工作。不是吗?phpinfo()将在第一个块中执行。现在if语句的值不会为true,所以我在第一个块的末尾使用了phpinfo(),看看它是否有效,它确实有效。@brock,如果您对行require_注释一次(“Includes/inc_chinesesezodiacdb.php”)
它是否打印phpinfo?我删除了结束行,它的行为也一样。如果我注释掉require\u一次
语句,phpinfo()可以工作。我在该文件中没有任何die()或exit()语句,但我确实发现了问题。
<?php
$ErrorMsgs = array();
$DBConnect = @new mysqli("localhost", "root", "password", "chinese_zodiac");
if ($DBConnect->connect_error)
$ErrorMsgs[] = "The database server is not available."
. "Connect Error is "
. $mysqli->connect_errno
. " " . $mysqli->connect_error . ".";
?>