我有php包含的问题,如果我包含文件,我看到错误Object not found
。我不知道该怎么做..我试图改变文件的路径,但它没有帮助。我只看到错误...
HTML
<div id="search" class="fleft">
<form action="lib/search.php" method="post">
<input type="text" name="searchText" placeholder="Search tweet!">
<input type="submit" name="search" value="Search"/>
</form>
</div>
<ul id="tweetDisplay">
<p>Tweets: </p>
<?php
include 'lib\search.php';
$searchQuery = $_SESSION['searchQuery'];
while($row = mysql_fetch_array($searchQuery)){
echo "----------------------------------------------";
echo "<li>Nickname: ".$row['nickname']."</li><li>".$row['text']."</li><li class='date'>".$row['pubdate']."</li>";
}
?>
</ul>
PhP脚本
<?php
include "connect.php";
session_start();
if ($_POST['searchText']){
$searchQuery = mysql_query("SELECT u.nickname, t.text, t.pubdate FROM 111212_tweets t INNER JOIN 111212_users AS u ON t.user_id = u.id WHERE t.text LIKE '%" . $_POST['searchText'] . "%' ORDER BY t.pubdate DESC");
$_SESSION['searchQuery'] = $searchQuery;
header('Location: ../main.php');
}else {
$searchQuery = mysql_query("SELECT u.nickname, t.text, t.pubdate FROM 111212_tweets t INNER JOIN 111212_users AS u ON t.user_id = u.id ORDER BY t.pubdate DESC");
$_SESSION['searchQuery'] = $searchQuery;
header('Location: ../main.php');
}
?>
答案 0 :(得分:0)
您使用的是Windows吗?如果是,您需要在路径中使用双斜杠:include 'lib\\search.php';
更新:您需要插入<?php session_start(); ?>
或将您的文件包含在第一个文件的顶部。
您有错误,因为您在php输出数据之后在第二个文件中调用session_start();
,并且在将任何输出发送到浏览器之前需要调用session_start();
。
更新:更改header('Location: ../main.php');
的{{1}}
您需要删除第二个重定向(标题位置):
header('Location: main.php');