我有一个php文件。我写了一些HTML代码,然后插入一些PHP。
问题是在浏览器中将php打印为纯文本,这很奇怪,我不知道如何解决它。
这是index.php
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Make-up blog">
<meta name="author" content="Rodrigo Ramos">
<title>Dreams & Feels</title>
<link rel="icon" href="../img/icon.PNG">
<!-- Bootstrap core CSS -->
<link href="../css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="../style.css" rel="stylesheet" type="text/css/">
</head>
<body>
<!-- NAVBAR
================================================== -->
<div class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
<img src="../img/logo_small.png" href="../index" class="visible-xs pull-left img-responsive">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav list-inline pull-left">
<li class="active"><a href="../index"><span class="glyphicon glyphicon-home"></span> Home</a>
<li ><a href="new_tutorial">Insert new Tutorial</a></li>
<li class="disabled"><a href="#">Make-Up Store</a></li>
</ul>
<ul class="nav navbar-nav pull-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Idioma<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Español</a></li>
<li><a href="#">Inglés</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Otro idioma</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<!-- END NAVBAR -->
<!-- Thumbnails -->
<?php
$mysqliHost = 'localhost';
$mysqliUsername = 'root';
$mysqliPassword = '';
$mysqliDatabase = 'dreams-feels';
// open mysqli db connection
$mysqli = new mysqli($mysqliHost,$mysqliUsername,$mysqliPassword,$mysqliDatabase);
// query for the articles in the db
$query_tutorial = 'SELECT tutorial_ID, title, description, url FROM tutorials';
$result_tutorial = $mysqli->query($query_tutorial);
echo '<div class="container" id="thumb_id">
<div class="row">';
if (!$result_tutorial)
{
printf("Error: %s\n", mysqli_error($mysqli));
exit();
}
$counter=0;
while($row_t = mysqli_fetch_array($result_tutorial))
{
// query for the article's image in the db
$query = "SELECT images.data FROM jnct_tutorials_images INNER JOIN images ON nct_tutorials_images.image_FK = images.image_ID WHERE jnct_tutorials_images.tutorial_ID = ".$row_t[0];
$result_images = $mysqli->query($query);
echo '<div class="col-xs-12 col-sm-6 col-md-6">
<div class="thumbnail">
<h2 class="text-center">'.$row_t[1].'</h2>
<img src="data:image;base64, '.base64_encode( $row_i[0] ).'" class="img-rounded img-responsive">
<div class="caption">
<p>'.substr($row_t[2], 0, 210).'...</p>
<a href="#" class="btn btn-danger" data-toggle="modal" data-target="#Modal'.$counter.'">VIDEO</a>
<div class="modal fade" id="Modal'.$counter.'" tabindex="-1" role="dialog" aria-labelledby="largeModal" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">'.$row_t[1].'</h4>
</div>
<div class="modal-body ">
<div class="embed-responsive embed-responsive-16by9">
<iframe id="Video'.$counter.'" class="embed-responsive-item" src="'.$row_t[3].'" allowfullscreen="allowfullscreen" mozallowfullscreen="mozallowfullscreen" msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" webkitallowfullscreen="webkitallowfullscreen"></iframe>
</div>
<hr>
<p><a class="btn" data-toggle="collapse" data-target="#viewdetails">View details »</a></p>
<p class="collapse" id="viewdetails">'.$row_t[2].'</p>
<hr>
<p><a class="btn" data-toggle="collapse" data-target="#viewproducts">View products used »</a></p>
<div class="container collapse" id="viewproducts">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>';
$counter++;
}
echo '</div>
</div>';
?>
<!-- END Thumbnails -->
<!-- START THE FEATURETTES -->
<div class="container">
<hr>
<div class="row featurette">
<div class="col-md-7">
<h2 class="featurette-heading">First featurette heading. <span class="text-muted">It'll blow your mind.</span></h2>
<p class="lead">Donec ullamcorper nulla non metus auctor fringilla. Vestibulum id ligula porta felis euismod semper. Praesent commodo cursus magna, vel scelerisque nisl consectetur. Fusce dapibus, tellus ac cursus commodo.</p>
</div>
<div class="col-md-5">
<img class="featurette-image img-responsive center-block" data-src="holder.js/500x500/auto" alt="Generic placeholder image">
</div>
</div>
<hr>
<div class="row">
<div class="col-md-7 col-md-push-5">
<h2>Oh yeah, it's that good. <span class="text-muted">See for yourself.</span></h2>
<p class="lead">Donec ullamcorper nulla non metus auctor fringilla. Vestibulum id ligula porta felis euismod semper. Praesent commodo cursus magna, vel scelerisque nisl consectetur. Fusce dapibus, tellus ac cursus commodo.</p>
</div>
<div class="col-md-5 col-md-pull-7">
<img class="-image img-responsive center-block" data-src="holder.js/500x500/auto" alt="Generic placeholder image">
</div>
</div>
<hr>
<div class="row">
<div class="col-md-7">
<h2>And lastly, this one. <span class="text-muted">Checkmate.</span></h2>
<p class="lead">Donec ullamcorper nulla non metus auctor fringilla. Vestibulum id ligula porta felis euismod semper. Praesent commodo cursus magna, vel scelerisque nisl consectetur. Fusce dapibus, tellus ac cursus commodo.</p>
</div>
<div class="col-md-5">
<img class="img-responsive center-block" src="">
</div>
</div>
<hr>
</div>
<!-- /END THE FEATURETTES -->
<!-- JavaScript for youtube videos -->
<script type="text/javascript" src="http://www.youtube.com/player_api"></script>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</body>
</html>
除页眉和页脚外,还会打印出来:
查询($ query_tutorial);回声' “; if(!$ result_tutorial){printf(“Error:%s \ n”,mysqli_error($ mysqli));出口(); } $ counter = 0; while($ row_t = mysqli_fetch_array($ result_tutorial)){//在db $ query中查询文章的图像=“SELECT images.data FROM jnct_tutorials_images INNER JOIN images ON nct_tutorials_images.image_FK = images.image_ID WHERE jnct_tutorials_images.tutorial_ID =”。 $ row_t [0]; $ result_images = $ mysqli-&gt; query($ query); echo'
我疯了!!!!
提前致谢