好吧,基本上,我有一个专用服务器(我无法访问它,我的朋友可以访问),并且当我为自己编写搜索栏时出错,并且PHP文件甚至都无法加载!我不知道为什么。
我尝试检查数据库是否正确连接,并且无法正常工作。
<?php
if($_GET['q'] == 'Search...'){
header('Location: index.php')
}
if($_GET['q'] !== '') {
$con = mysql_connect('localhost', 'admin_search', 'Search');
$db = mysql_select_db('admin_search');
?>
<html>
<head>
<title>Website In Maintenance</title>
<link rel="stylesheet" href="css/style.css">
<script type="text/javascript" href="js/app.js"></script>
<form action="index.php" method="GET" id="searchForm">
<input type='text' name="q" id='searchBar' placeholder="" value="Search..." maxlength="50" autocomplete="off" onMouseDown="" onBlur=""/>
<input type="submit" id="searchBtn" value="Go!" />
</form>
</head>
<body>
</body>
<?php
if(!isset($q)){
echo '';
} else {
$query = mysql_query("SELECT * FROM search WHERE title LIKE '%$q%' OR description LIKE '%$q%'");
$num_rows = mysql_num_rows($query);
?>
<p><strong><?php echo $num_rows; ?></strong> results for '<?php echo $q; ?>'</p>
<?php
while($row = mysql_fetch_array($query)) {
$id = $row['id'];
$title = $row['title'];
$desc = $row['description'];
echo '<h3><a href="' . $id . '.php">' . $title . '</a></h3><p>' . $desc . '</p><br />';
}
}
?>
</html>
<?php
} else {
header('Location: index.php');
}
?>
没有错误,但HTTP错误500。