Joseph Witchard
07-21-2009, 08:24 AM
<?php
/** Coded by: Jeffrey (Joseph Witchard)
** Created on: 07/20/09
** Last modified: 07/21/09
** Purpose: To search for specific
** Rebirth news and display
** it to the user. */
// strip BBCode
require('path_to_bb_function');
// set up the connection
require('path_to_connection_function');
$conn = @connect_function();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<title>News Search Results -- Ultimate Hogwarts: The Rebirth</title>
<?php include('includes/meta_info.html'); ?>
<link href="/css/general.css" rel="stylesheet" type="text/css"/>
<link href="/css/homepage.css" rel="stylesheet" type="text/css"/>
<link href="/css/main_pages.css" rel="stylesheet" type="text/css"/>
<link href="/css/ticker.css" rel="stylesheet" type="text/css"/>
<link href="/favicon.ico" rel="shortcut icon"/>
<script type="text/javascript" src="/javascripts/scroll.js"></script>
</head>
<body>
<div id="wrapper">
<?php include('path_to_headers'); ?>
<div id="navigation">
<?php include('path_to_navigationl'); ?>
</div>
<div id="right">
<?php include('path_to_news_scroller.'); ?>
<div id="rightAd">
<?php include('path_to_google_adl'); ?>
</div>
</div>
<div align="center" id="center">
<h3>Search Results</h3>
<div id="news">
<?php
if (mysqli_connect_error())
{
// get ready to mail me the error
define('TO', 'josephwitchard@uhrebirth.com');
define('SUBJECT', 'Rebirth Database Connection Error');
$headers = "From: Rebirth Databases <rebirth_databases@uhrebirth.com> \r\n";
$headers .= "Reply-To: Rebirth Databases <rebirth_databases@uhrebirth.com> \r\n";
$message = "There was a connection error on " . DB_NAME . " at uhrebirth.com" . $_SERVER['PHP_SELF'] . ". The error returned was: " . mysqli_connect_error();
// send the message
mail(TO, SUBJECT, $message, $headers);
echo "<p class='warning'>There was an error when connecting to the database. The webmaster has been notified of this error. Please try again later.</p>";
exit;
}
if (array_key_exists('search', $_POST) && !empty($_POST['search']))
{
// set up required and expected fields
$required = array('searching');
$expected = array('searching');
// set up an empty array for missing fields
$missing = array();
// process the post variables
foreach ($_POST as $key => $value)
{
// assign to a temporary variable and strip whitespace if not an array
$temp = is_array($value) ? $value : trim($value);
if (empty($temp) && in_array($key, $required))
{
// add to missing
$missing[] = $key;
}
elseif (in_array($key, $expected))
{
// assign to a variable of the same name
${$key} = $temp;
}
}
// go ahead only if missing is empty
if (empty($missing))
{
// we no longer need missing
unset($missing);
// begin preparing the search term for searching
$searching = htmlentities($searching, ENT_QUOTES);
$searching = $conn->real_escape_string($searching);
$search_length = strlen($searching) + 2;
$searching = str_pad($searching, $search_length, '%', STR_PAD_BOTH);
// start the query
$query1 = "SELECT COUNT(*) FROM posts WHERE post_body LIKE '$searching'";
/** Coded by: Jeffrey (Joseph Witchard)
** Created on: 07/20/09
** Last modified: 07/21/09
** Purpose: To search for specific
** Rebirth news and display
** it to the user. */
// strip BBCode
require('path_to_bb_function');
// set up the connection
require('path_to_connection_function');
$conn = @connect_function();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<title>News Search Results -- Ultimate Hogwarts: The Rebirth</title>
<?php include('includes/meta_info.html'); ?>
<link href="/css/general.css" rel="stylesheet" type="text/css"/>
<link href="/css/homepage.css" rel="stylesheet" type="text/css"/>
<link href="/css/main_pages.css" rel="stylesheet" type="text/css"/>
<link href="/css/ticker.css" rel="stylesheet" type="text/css"/>
<link href="/favicon.ico" rel="shortcut icon"/>
<script type="text/javascript" src="/javascripts/scroll.js"></script>
</head>
<body>
<div id="wrapper">
<?php include('path_to_headers'); ?>
<div id="navigation">
<?php include('path_to_navigationl'); ?>
</div>
<div id="right">
<?php include('path_to_news_scroller.'); ?>
<div id="rightAd">
<?php include('path_to_google_adl'); ?>
</div>
</div>
<div align="center" id="center">
<h3>Search Results</h3>
<div id="news">
<?php
if (mysqli_connect_error())
{
// get ready to mail me the error
define('TO', 'josephwitchard@uhrebirth.com');
define('SUBJECT', 'Rebirth Database Connection Error');
$headers = "From: Rebirth Databases <rebirth_databases@uhrebirth.com> \r\n";
$headers .= "Reply-To: Rebirth Databases <rebirth_databases@uhrebirth.com> \r\n";
$message = "There was a connection error on " . DB_NAME . " at uhrebirth.com" . $_SERVER['PHP_SELF'] . ". The error returned was: " . mysqli_connect_error();
// send the message
mail(TO, SUBJECT, $message, $headers);
echo "<p class='warning'>There was an error when connecting to the database. The webmaster has been notified of this error. Please try again later.</p>";
exit;
}
if (array_key_exists('search', $_POST) && !empty($_POST['search']))
{
// set up required and expected fields
$required = array('searching');
$expected = array('searching');
// set up an empty array for missing fields
$missing = array();
// process the post variables
foreach ($_POST as $key => $value)
{
// assign to a temporary variable and strip whitespace if not an array
$temp = is_array($value) ? $value : trim($value);
if (empty($temp) && in_array($key, $required))
{
// add to missing
$missing[] = $key;
}
elseif (in_array($key, $expected))
{
// assign to a variable of the same name
${$key} = $temp;
}
}
// go ahead only if missing is empty
if (empty($missing))
{
// we no longer need missing
unset($missing);
// begin preparing the search term for searching
$searching = htmlentities($searching, ENT_QUOTES);
$searching = $conn->real_escape_string($searching);
$search_length = strlen($searching) + 2;
$searching = str_pad($searching, $search_length, '%', STR_PAD_BOTH);
// start the query
$query1 = "SELECT COUNT(*) FROM posts WHERE post_body LIKE '$searching'";