我想从数据库输出PHP代码,但代码看起来像浏览器中的注释
我的英语对此抱歉。第一张图片是包含id,title,filmname的数据库,
我插入'filmname'这个php代码(<?php include ('includes/search.php');?>
)第二个图像(这是viewsource屏幕)就是当我点击搜索栏并得到结果但是来自数据库(<?php include ('includes/search.php');?>
)的代码是喜欢评论。我可以输出数据库html代码(解码html代码)和它在结果中工作,但不是PHP。
包括/ - &gt;夹
search.php - &gt;我有这个文件,这是.php))
我创建了搜索栏,点击后得到结果,html代码没有问题,但是php代码没有
id int auto increment
title varchar
电影名称文字
请帮帮我
引导链接上的图像:
index.php
<!DOCTYPE html>
<html>
<title>Home page</title>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="css/style.css" />
<link rel="stylesheet" href="font_awesome/css/font-awesome.min.css">
<style>
.pic {
position: fixed;
top: 10%;
left: 0px;
}
</style>
</head>
<body>
<?php include ('includes/top.php'); ?>
<?php include ('includes/search.php'); ?>
<div class="main">
<?php include ('filmler/starwarsrogueone_s.php'); ?>
<?php include ('filmler/starwarsrogueone_s.php'); ?>
</div> <!-- main -->
<div class="pic">
<img src="islandjedi.jpg" width="100%" height="100%"></img>
</div>
<?php include ('includes/left_side.php'); ?>
<?php include ('includes/right_side.php'); ?>
<script type="text/javascript" src="js/klik_count.js"></script>
<?php include ('includes/bottom.php'); ?>
</body>
</html>
的search.php
<div class="top_searchbox">
<div class="search_fix">
<form name="search" method="post" action="axtaris_neticesi.php">
<input type="search" name="query" placeholder="Axtarış...">
<button type="submit" onclick="window.location.href='axtaris_neticesi.php">Axtar</button>
</form>
</div>
</div>
axtaris_neticesi.php
<?php include ('includes/connect.php'); ?>
<!DOCTYPE html>
<html>
<title>Home page</title>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="css/style.css" />
<link rel="stylesheet" href="font_awesome/css/font-awesome.min.css">
</head>
<body>
<?php include ('includes/top.php'); ?>
<?php include ('includes/search.php'); ?>
<div class="main">
<?php include ('includes/axtar_db.php'); ?>
</div>
<?php include ('includes/left_side.php'); ?>
<?php include ('includes/right_side.php'); ?>
<?php include ('includes/bottom.php'); ?>
</body>
</html>
axtar_db.php
<?php
$query = $_POST['query'];
// gets value sent over search form
$min_length = "";
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then
$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to >
$query = mysqli_real_escape_string($con,$query);
// makes sure nobody uses SQL injection
$raw_results = mysqli_query($con,"SELECT * FROM axtaris
WHERE (`title` LIKE '%".$query."%')") or die('sehv tapildi');
// * means that it selects all fields, you can also write: `id`, `title`, `text`
// articles is the name of our table
// '%$query%' is what we're looking for, % means anything, for example if $query is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use `title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %' ...OR ... '$query %' ... OR ... '% $query'
if(mysqli_num_rows($raw_results) > 0){ // if one or more rows are returned do following
while($results = mysqli_fetch_array($raw_results)){
// $results = mysqli_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop
//echo "<p><h3>".$results['filmname']."</p>";
echo htmlspecialchars_decode(stripslashes($results['filmname']));
// posts results gotten from database(title and text) you can also show id ($results['id'])
}
}
else{ // if there is no matching rows do following
echo "No results";
}
}
else{ // if query length is less than minimum
echo "Minimum length is ".$min_length;
}
?>
数据库图片下行链接(数据库)
答案 0 :(得分:0)
关于您发布的代码有很多可以改进的内容,但重点是在您的网页上嵌入YouTube视频,这会在屏幕上显示您想要的视频......
在您的数据库表格中,将filename
列值设置为4Q9jBomjpJU
,以便在youtube上标识您的目标视频。
当您的查询返回此值时,请按照此处的说明操作:How to add YouTube video as <video> instead of an embedded <iframe>?(还有网络上的其他许多教程)并将$results['filmname']
值写入html块的正确位置,使用
<?php echo $results ['filmname']; ?>
(如果你愿意,可以使用简短的php标签)。
这是另一条教学链接:
答案 1 :(得分:0)
要在浏览器中输出数据库中的数据而不将其解释为“实时”HTML代码,您必须使用htmlspecialchars()
。您可能希望将输出放在<pre>
标记内,以便使用等宽字体(如IDE)格式化。
// assume you read the data from the database here
$data = "<?php include('includes/search.php'); ?>";
echo "<pre>";
echo htmlspecialchars($data);
echo "</pre>";
同样,这只会显示PHP代码,它不会执行它。因此,用户将在其浏览器中看到<?php include('includes/search.php'); ?>
代码。