我试图显示我的数据库中已被MySql查询提取的信息。我设置了这个错误
Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\1\search.php on line 14
以下是search.php的代码
<?php
if (isset($_POST['searchterm'])){
mysql_connect("localhost","root","Oliver");
mysql_select_db("videos");
$search = mysql_real_escape_string(trim($_POST['searchterm']));
$find_videos = mysql_query("SELECT * FROM `videos` WHERE `keywords` LIKE'%$search%'");
while($row = mysql_fetch_assoc($find_videos))
{
$name = $row['name'];
echo "<table">";
echo "<tr>";
echo "<td>$name</td>";
echo "</tr>";
echo "<tr>";
echo "<td>$name</td>";
echo "</tr>";
echo "</table>";
}
}
?>
<?php
include('session.php');
?>
<!DOCTYPE html>
<html>
<head>
<link href="http://vjs.zencdn.net/4.12/video-js.css" rel="stylesheet">
<link rel="icon" type="image/ico" href="images/favicon.ico">
<script src="http://vjs.zencdn.net/4.12/video.js"></script>
<link href="http://vjs.zencdn.net/4.12/video-js.css" rel="stylesheet">
<script src="http://vjs.zencdn.net/4.12/video.js"></script>
<style type="text/css">
.vjs-default-skin .vjs-control-bar { font-size: 125% }
</style>
<meta charset="utf-8">
<title>Network TV | search</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/bootstrap.css" />
<link href="css/font-awesome.css" rel="stylesheet" />
<link href="css/3.1.1/animate.css" rel="stylesheet" />
<link rel="stylesheet" href="css/styles.css" />
</head>
<body style="overflow-x: hidden">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Network TV</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class=""><a href="\1\index.php">Home</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="js/scripts.js"></script>
</html>
我已经有表单设置将信息发布到此页面。显示信息时,它只是悬挂在屏幕左上方的列表中,我试图将其显示在屏幕左侧的一个表格中。以下是我尝试过的一些例子。
echo "<table style=text-align:center">"";
echo "<tr>";
echo "<td>$name</td>";
echo "</tr>";
echo "<tr>";
echo "<td>$name</td>";
echo "</tr>";
echo "</table>";
这给了我错误Parse error: syntax error, unexpected '"<table style="' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';' in C:\xampp\htdocs\1\search.php on line 13
然后我试过了。
echo "<table style=""width:100%">";
echo "<tr>";
echo "<td>Jill</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Eve</td>";
echo "</tr>";
echo "</table>";
我收到错误
Parse error: syntax error, unexpected '"width:100%"' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';' in C:\xampp\htdocs\1\search.php on line 14
我不知道什么是错的。任何帮助都非常感谢
标记为重复 我不知道我在修什么,所以不幸的是它对我毫无帮助。我相信它会帮助其他人以后下线。
图片和更新 这是一个现在看起来如何的图像。
正如您所看到的,每次都会重复“电影名称”。
代码更新
echo '<table style="width:100%">';
echo "<tr>";
echo "<td>Name of movie</td>";
echo "</tr>";
echo "<tr>";
echo "<td>$name</td>";
echo "</tr>";
echo "</table>";
更新2
<?php
if (isset($_POST['searchterm'])){
mysql_connect("localhost","root","Oliver");
mysql_select_db("videos");
$search = mysql_real_escape_string(trim($_POST['searchterm']));
$find_videos = mysql_query("SELECT * FROM `videos` WHERE `keywords` LIKE'%$search%'");
while ($row = mysql_fetch_array($find_videos, MYSQL_BOTH)) {
{
$name = $row['name'];
}
}
}
?>
<?php
include('session.php');
?>
<!DOCTYPE html>
<html>
<head>
<link href="http://vjs.zencdn.net/4.12/video-js.css" rel="stylesheet">
<link rel="icon" type="image/ico" href="images/favicon.ico">
<script src="http://vjs.zencdn.net/4.12/video.js"></script>
<link href="http://vjs.zencdn.net/4.12/video-js.css" rel="stylesheet">
<script src="http://vjs.zencdn.net/4.12/video.js"></script>
<style type="text/css">
.vjs-default-skin .vjs-control-bar { font-size: 125% }
</style>
<meta charset="utf-8">
<title>Network TV | search</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/bootstrap.css" />
<link href="css/font-awesome.css" rel="stylesheet" />
<link href="css/3.1.1/animate.css" rel="stylesheet" />
<link rel="stylesheet" href="css/styles.css" />
</head>
<body style="overflow-x: hidden">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Network TV</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class=""><a href="\1\index.php">Home</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="v-center">
<h1 class="text-center" style="color:white">Welcome to Network TV</h1>
<table class="table" style="width:10%">
<thead>
<tr>
<th>Movie name</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $name; ?></td>
</tr>
</tbody>
</table>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="js/scripts.js"></script>
</html>