在php中,如果查询失败,文件include将不工作
当mysql查询失败时,我将在中包含一个php文件。包含的文件不工作。以下是不起作用的代码段。请查收在php中,如果查询失败,文件include将不工作,php,mysql,Php,Mysql,当mysql查询失败时,我将在中包含一个php文件。包含的文件不工作。以下是不起作用的代码段。请查收 $countsql2='SELECT * from table_name'; $countsql3 = mysqli_query($mysqli, $countsql2) or die(" <div id='fail_container'> <div id='fail_grid'> <span class='searched_invalid
$countsql2='SELECT * from table_name';
$countsql3 = mysqli_query($mysqli, $countsql2) or die("
<div id='fail_container'>
<div id='fail_grid'>
<span class='searched_invalid'>There seems to be an issue with the server connectivity.Please Try again later.</span><br />
<span class='searched_invalid'>We have an option to check out the categories here</span>
</div>
</div>"
include 'file1.php');
$countsql2='SELECT*from table_name';
$countsql3=mysqli\u查询($mysqli,$countsql2)或die('
服务器连接似乎有问题。请稍后再试。
我们可以选择在这里查看类别
"
包括“file1.php”);
我想在查询失败时显示包含的php文件。但当我移除模具中的包含部分时,它运行良好。但我想用include php文件运行它
请帮助我更正此问题,或者是否可以通过其他方式进行更正。您应该在
if
语句中执行此操作,如下所示:
$countsql2='SELECT * from table_name';
$countsql3 = mysqli_query($mysqli, $countsql2);
if (!$countsql3) {
echo "<div id='fail_container'>
<div id='fail_grid'>
<span class='searched_invalid'>There seems to be an issue with the server connectivity.Please Try again later.</span><br />
<span class='searched_invalid'>We have an option to check out the categories here</span>
</div>
</div>"
include 'file1.php';
exit;
}
$countsql2='SELECT*from table_name';
$countsql3=mysqli\u查询($mysqli,$countsql2);
如果(!$countsql3){
回声“
服务器连接似乎有问题。请稍后再试。
我们可以选择在这里查看类别
"
包括“file1.php”;
出口
}
这是因为停止了应用程序
你能做的是:
if ( !$countsql3 = mysqli_query( $mysqli, $countsql2 ) )
{
echo "<div id='fail_container'>
<div id='fail_grid'>
<span class='searched_invalid'>There seems to be an issue with the server connectivity.Please Try again later.</span><br />
<span class='searched_invalid'>We have an option to check out the categories here</span>
</div>
</div>";
include('file1.php');
die;
}
if(!$countsql3=mysqli\u查询($mysqli,$countsql2))
{
回声“
服务器连接似乎有问题。请稍后再试。
我们可以选择在这里查看类别
";
包括('file1.php');
死亡
}
您应该尝试以下完整路径
file1.php
如果file1.php仍然没有显示,您可以尝试使用$\u服务器[“DOCUMENT\u root]”获取根文件夹编码>并添加当前位置
error_reporting(E_ALL);
ini_set('display_errors', 1);
$countsql2='SELECT * from table_name';
if ( !$countsql3 = mysqli_query( $mysqli, $countsql2 ) )
{
echo "<div id='fail_container'>
<div id='fail_grid'>
<span class='searched_invalid'>There seems to be an issue with the server connectivity.Please Try again later.</span><br />
<span class='searched_invalid'>We have an option to check out the categories here</span>
</div>
</div>";
require('/full/path/to/file/file1.php');
}
错误报告(E_ALL);
ini设置(“显示错误”,1);
$countsql2='SELECT*fromtable_name';
if(!$countsql3=mysqli\u查询($mysqli,$countsql2))
{
回声“
服务器连接似乎有问题。请稍后再试。
我们可以选择在这里查看类别
";
要求('/full/path/to/file/file1.php');
}
die
函数只接受一个字符串参数,并将输出相同的参数。您不能将包含函数传递给它。在包含行之前不应该有冒号吗?仍然没有显示file1.php,先生。仍然没有显示file1.php,先生。@micheal您有任何错误吗?您还检查了文件路径是否正确吗?是的。我检查了文件路径是否正确。不显示任何错误尝试启用更高级别的错误报告:error\u reporting(E\u ALL);ini设置(“显示错误”,1)代码>