I found some code using pdo for the search engine, which is easier to read etc... and I am getting the following message when running the code.
Fatal error: Call to a member function prepare() on a non-object in /home/ubuntu/workspace/test/test2.php on line 28
<?php
// starts a session
session_start();
//include files
include 'header/header.php';
include 'nav/navigation.php';
include 'init.php';
//convert string time to time
$expires = strtotime($_POST["expires"]);
$expires = date('Y-m-d', $expires);
//if
if(isset($_POST['search'])){
$search_string = trim($_POST['keyword']);
if(strlen($search_string) == 0)
{
//The user is looking for empty string...
//as the user may have hit search by error
}
$keywords = explode(" ", $_POST["search"]);
foreach($keywords as $keyword)
{
$keyword = trim($keyword);
$stmt = $dbh->prepare("SELECT * FROM event WHERE (eventName LIKE ?
OR eventLocation LIKE ? OR commencing LIKE ? OR expires LIKE ?)");
$stmt->execute(array("%$keyword%","%$keyword%","%$keyword%","%$keyword%"));
}
}
?>
<fieldset>
<legend><h2>Events</h2></legend>
<form name="search" method="post" action="<?=$PHP_SELF?>">
<tr> <th> <td>
<fieldset>
<legend>Find all events</legend>
<input type="checkbox" name="events" value="Yes" /> All events<br />
</fieldset>
<legend>Find events by date</legend>
<input type="date" name="date" min="<?php echo date("Y-m-d");?>"
max="2025-01-01" value="<?php echo date("Y-m-d");?>">
</fieldset>
<fieldset>
<legend>search for events</legend>
<form name="search" method="post" action= <?=$PHP_SELF?>>
Keyword: <input type="text" name="keyword" /> in
<Select NAME="field">
<Option VALUE="eventName">Event Name</option>
<Option VALUE="eventLocation">Event location</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="search" />
</fieldset>
</form>
</select> </td></tr>
<?php
//include files
include 'footer/footer.php';
?>
<script src="js/vendor/jquery.js"></script>
<script src="js/foundation.min.js"></script>
<script>
</script>
</body>