php - PHP代码在浏览器上显示空白屏幕而不是内容
问题描述
当我用网络浏览器打开它时,下面带有 html 的 php 代码显示一个空白屏幕。我已经设置了一个 php 服务器来运行它。我究竟做错了什么?
<!DOCTYPE html>
<html>
<head>
<title>maro</title>
<link rel="stylesheet" href="bootstrap.min.css">
<link rel="stylesheet" href="custom.css">
</head>
<body>
<div class="container-fluid">
<form action="imagesear.php" method="get">
<div class="row" id="bg">
<div class="col-sm-1" id="resdoodle">
<a href="index.html"><font color="#FF0000">m</font><font color="#FFA500">a</font><font color="#008000">r</font><font color="#0000FF">o</font></a>
</div>
<div class="col-sm-6" id="searchbx2">
<div class="input-group">
<input type="text" class="form-control" name="search" id="boxstyle2" required>
<span class="input-group-btn">
<input type="submit" class="btn btn-secondary" name="search_btn" value="GO" id="btnstyle2">
</span>
</div>
</div>
</div>
</form>
</div>
<div class="result">
<?php
$search=$_GET["id"];
$_con=mysqli_connect("localhost","augustus","password");
mysqli_select_db($_con,"websited");
$_sql2="select * from webd where stitle like '%$search%'";
$rs=mysqli_query($_con,$_sql2);
if(mysqli_num_rows($rs)<1)
{
echo "<center><h4><b>Oops! No result found for your query</b></h4></center>";
exit();
}
while($resul2=mysqli_fetch_assoc($rs))
{
echo "<a href='".$resul2['slink']."'><img src='".$resul2['simg']."' height='200px' id="imgp"></a> ";
}
?>
</div>
<script src="jquery.min.js"></script>
<script src="tether.min.js"></script>
<script src="bootstrap.min.js"></script>
</body>
</html>
我尝试对我的 php 服务器进行故障排除,但这很好,因为其他 php 代码运行良好。请帮助修复此代码
解决方案
对我来说,它返回了这个错误:
解析错误:语法错误,意外的 'imgp' (T_STRING),期待 ',' 或 ';' 在第 38 行的 /var/www/html/tmp/test.php 中
在这一行:
echo "<a href='".$resul2['slink']."'><img src='".$resul2['simg']."' height='200px' id="imgp"></a> ";
id="imgp" 在双引号内,在其他带双引号的字符串内。所以这就是问题所在。您需要将单引号放在其他带双引号的字符串中才能正常工作:
echo "<a href='".$resul2['slink']."'><img src='".$resul2['simg']."' height='200px' id='imgp'></a> ";
也许错误不会出现在您面前,因为它们已被禁用。你可以试试这个,在 php 文档的开头:
error_reporting(E_ALL);
PS:用户也会出现错误,请谨慎使用。
推荐阅读
- c# - C# 问题处理 SearchResultAttributeCollection LDAP 的内存使用情况
- rabbitmq - RabbitMQ 队列声明。最佳实践
- capistrano - capistrano 任务中配置的 nvm 版本未应用
- eclipse - ( Eclipse CDT ) 在 addCProjectDescriptionListener - handleEvent (CProjectDescriptionEvent 事件) -> 如何获得选定的配置?
- python - 有效地跟踪模拟观测值
- postgresql - Perl 中跨平台警报信号处理或执行超时最可靠的方法是什么?
- r - 如何在 Rstudio 中修改行到行自动滚动行为
- javascript - 打开远程引导模式
- html - A11Y - 屏幕阅读器不读取“aria-description”标签
- reactjs - 有没有办法用 react-test-renderer 测试 Chakra-ui 模态对话框?