php knowledge base search page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cjackson721
Forum Newbie
Posts: 3
Joined: Thu Sep 30, 2010 6:43 am
Location: Palatka, Florida, USA

php knowledge base search page

Post by cjackson721 »

Hey guys,

I'm new to PHP and I'm having a problem. I'm sure that it's just something that's really simple that I'm missing, but I'd be very grateful of any assistance y'all could provide. I'm in charge of my church's website and we have a lot of articles and videos on the site. I'm trying to build a search so that the user can sort all the content by category or submitter. I have built a mysql database with the required information and I thought I had the search code working. However, I now keep getting a blank page when I include "ob_start();" at the start of the page. When I remove "ob_start();", then I get the "headers sent" message. The page can be found at: http://www.trinitypalatka.com/onlineresources.php. Thanks in advance for your help.

The exact errors I get are:

Warning: Cannot modify header information - headers already sent by (output started at /home/content/c/h/r/chris5021/html/onlineresources.php:9) in /home/content/c/h/r/chris5021/html/onlineresources.php on line 318

Warning: Cannot modify header information - headers already sent by (output started at /home/content/c/h/r/chris5021/html/onlineresources.php:9) in /home/content/c/h/r/chris5021/html/onlineresources.php on line 319

Warning: Cannot modify header information - headers already sent by (output started at /home/content/c/h/r/chris5021/html/onlineresources.php:9) in /home/content/c/h/r/chris5021/html/onlineresources.php on line 320


And here is the full code for the page:

Code: Select all

<?php
ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Online Resources - Trinity Baptist Church - Palatka, FL</title>
</head>
<body>
<?php

echo"<link rel='stylesheet' type='text/css' href='coding/maincss.css' />";
echo"<script type='text/javascript' src='coding/navigationmenu.js'></script>";
echo"<script src='coding/sorttable.js'></script>";

echo"<style type='text/css'>
.style1 {
	font-family: Georgia, 'Times New Roman', Times, serif;
	font-size: 14px;
}
a:link {
	color: #900011;
}
a:visited {
	color: #900011;
}
a:hover {
	color: #900011;
}
a:active {
	color: #900011;
}
.style7 {font-family: Georgia, 'Times New Roman', Times, serif; font-size: 15px; }
body {
	background-color: #f7f7f7;
}
.style4 {	font-family: Arial, Helvetica, sans-serif;
	font-size: large;
	color: #900011;
}
.style18 {
	font-size: 18px;
	font-weight: bold;
}
.style19 {
	font-family: Arial, Helvetica, sans-serif;
	color: #FFFFFF;
	font-weight: bold;
	font-size: medium;
}
</style>";

$con = mysql_connect('servername', 'username', 'password');
if (!$con)
  {
  die('Could not connect, please try again later.<br>Error: ' . mysql_error()) ;
  }

mysql_select_db('servername', $con);

{
if(isset($_COOKIE['tbccategory'])){
$category = $_COOKIE['tbccategory'];
$author = $_COOKIE['tbcauthor'];
$criteria = "WHERE Category='$tbccategory' AND Submitter='$tbcauthor'";
{
$past = time() - 100; 
setcookie(tbccategory, gone, $past);
setcookie(tbcauthor, gone, $past);
}
}
else {
$criteria = "";
}
}

?>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td background="Images/background-top2.png"><table width="1000" height="200" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="620" height="100%" valign="bottom"><a href="index.html"><img src="Images/TrinityLogoWeb.png" width="500" height="180" border="0"></a></td>
        <td width="340" align="center" valign="bottom">
            <div align="center">
              &nbsp;&nbsp;
              <table width="276" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="276" align="left" valign="bottom"><p align="right"><span class="style7"><img src="Images/PuzzlePiece.png" width="28" height="17"><span class="style1"><a href="areyoumissingapieceofthepuzzle.html">Are You Missing a Piece of the Puzzle?</a></span></span></p>

					<form action="http://www.trinitypalatka.com/searchresults.html" id="cse-search-box">
  <div>
    <div align="right">
      <p>
        <input type="hidden" name="cx" value="016442380590868967410:cesbaqqypzy" />
        <input type="hidden" name="cof" value="FORID:11" />
        <input type="hidden" name="ie" value="UTF-8" />
        <input type="text" name="q" size="20" />
        <input type="submit" name="sa" value="Search" />
      <br>
      </p>
    </div>
  </div>
</form>
                    <div align="right">
                      <script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
                      <script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
                      <script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
                  </div></td>
                </tr>
              </table>
          </div></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td background="Images/background-middle2.png"><table width="1000" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="240" align="center" valign="top"><p><div id="dhtmlgoodies_slidedown_menu">
			<ul>
              <li><a href="index.html">Home</a></li>
              <li><a href="#">About Trinity </a>
                  <ul>
                    <li><a href="whatdowebeleive.html">What Do We Believe? </a></li>
                    <li><a href="whoarewe.html">Who Are We? </a></li>
                    <li><a href="worshipservices.html">Service Times</a></li>
                    <li><a href="directions.html">Directions</a></li>
                  </ul>
              </li>
              <li><a href="contacttrinity.html">Contact Trinity</a></li>
              <li><a href="#">Sermons/Services</a>
                  <ul>
                    <li><a href="sermons.html">Sermon Archives </a></li>
                    <li><a href="livefeed.html">Live Services </a></li>
                    <li><a href="worshipservices.html">Service Times </a></li>
                    <li><a href="directions.html">Directions</a></li>
                  </ul>
              </li>
              <li><a href="#">Ministries</a>
                  <ul>
                    <li><a href="worshipservices.html">Worship Services</a></li>
                    <li><a href="networkgroups.html">Network Groups </a></li>
                    <li><a href="youth.html">Youth</a></li>
                    <li><a href="SWAG.html">SWAG</a></li>
                  </ul>
              </li>
              <li><a href="calendar.html">Church Calendar</a></li>
              <li><a href="monthlynewsletter.html">Monthly Newsletter</a> </li>
              <li><a href="#">Bible FAQs </a>
                  <ul>
                    <li><a href="5featuredfaqs.html">5 Featured FAQs</a></li>
                    <li><a href="5mostrecentfaqs.html">5 Most Rescent FAQs</a></li>
                    <li><a href="viewallfaqs.html">View All FAQs</a> </li>
                  </ul>
              </li>
              <li><a href="#">Resources</a>
                  <ul>
                    <li><a href="onlineresources.html">All Online Resources</a></li>
                    <li><a href="recommendedreading.html">Recommended Reading </a></li>
                    <li><a href="dangerousbooks.html">Dangerous Books</a></li>
                    <li><a href="readthebiblein1year.html">Read the Bible in 1 Year</a></li>
                  </ul>
              </li>
              <li><a href="onlinegiving.html">Online Giving</a> </li>
              <li><a href="links.html">Links</a></li>
			  </ul></p>
			

		</div>
		
		<div id="newsletter">
		Sign up for our<br>
		Monthly Newsletter<br><br>
		<form action="http://trinitypalatka.us1.list-manage.com/subscribe/post?u=071138b10d1ed4ebcd19db57f&id=2311fdafde" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" style="font: normal 100% Arial;font-size: 12px;">
		<label for="mce-EMAIL">Email Address<strong class="note-required">*</strong></label><br>
                <input name="EMAIL" type="text" class="required email" id="mce-EMAIL" value="" size="25"><br><br>
		<label for="mce-FNAME">First Name</label><br>
                <input type="text" value="" name="FNAME" class="" id="mce-FNAME" size="25"><br><br>
		<label for="mce-LNAME">Last Name</label><br>
                <input type="text" value="" name="LNAME" class="" id="mce-LNAME" size="25"><br><br>
		<label class="input-group-label">Email Format</label><br>
                <input type="radio" value="html" name="EMAILTYPE" id="mce-EMAILTYPE-0">
        <label for="mce-EMAILTYPE-0">html</label>
                <input type="radio" value="text" name="EMAILTYPE" id="mce-EMAILTYPE-1">
        <label for="mce-EMAILTYPE-1">text</label>
                <input type="radio" value="mobile" name="EMAILTYPE" id="mce-EMAILTYPE-2">
        <label for="mce-EMAILTYPE-2">mobile</label><br><br>
		<input type="submit" value="Sign me up!" name="subscribe" id="mc-embedded-subscribe" class="btn">
		</form>
		</div>
		
		<script type="text/javascript">
		initSlideDownMenu();
		</script>
		
		</td>
        <td width="680" align="center" valign="top"><p>&nbsp;</p>
          <p class="style4 style18">All Online Resources</p>
          <p>This is the database of all the online resources found on our website. </p>
          <p><form id="filter" action="" method="post">
			    <p>Filter Resources by Subject:</p>
			    <p>
			      <select name="select" id="select">
				    <option value="select_all" >All Subjects</option>
				    <option value="select_apologetics">Apologetics</option>
				    <option value="select_bible_study">Bible Study</option>
				    <option value="select_blessings">Blessings</option>
				    <option value="select_change">Change</option>
				    <option value="select_children">Children</option>
				    <option value="select_christmas">Christmas</option>
				    <option value="select_church">Church</option>
				    <option value="select_cremation">Cremation</option>
				    <option value="select_curses">Curses</option>
				    <option value="select_dinosaurs">Dinosaurs</option>
				    <option value="select_discipleship">Discipleship</option>
				    <option value="select_evangelism">Evangelism</option>
				    <option value="select_evolution">Evolution</option>
				    <option value="select_family">Family</option>
				    <option value="select_fathers">Fathers</option>
				    <option value="select_fellowship">Fellowship</option>
				    <option value="select_giving">Giving</option>
				    <option value="select_goals">Goals</option>
				    <option value="select_gods_will">God's Will</option>
				    <option value="select_graphs">Graphs</option>
				    <option value="select_history">History</option>
				    <option value="select_holidays">Holidays</option>
				    <option value="select_holy_spirit">Holy Spirit, the</option>
				    <option value="select_home">Home</option>
				    <option value="select_husbands">Husbands</option>
				    <option value="select_jesus">Jesus</option>
				    <option value="select_life">Life</option>
				    <option value="select_lords_supper">Lord's Supper, the</option>
				    <option value="select_love">Love</option>
				    <option value="select_maps">Maps</option>
				    <option value="select_mothers">Mothers</option>
				    <option value="select_occult">Occult, the</option>
				    <option value="select_offerings">Offerings</option>
				    <option value="select_perseverance">Perseverance</option>
				    <option value="select_prayer">Prayer</option>
				    <option value="select_rebuilding">Rebuilding</option>
				    <option value="select_sacraments">Sacraments</option>
				    <option value="select_service">Service</option>
				    <option value="select_spiritual_gifts">Spiritual Gifts</option>
				    <option value="select_spiritual_health">Spiritual Health</option>
				    <option value="select_suffering">Suffering</option>
				    <option value="select_suicide">Suicide</option>
				    <option value="select_tattoos">Tattoos</option>
				    <option value="select_testimony">Testimony</option>
				    <option value="select_thanksgiving">Thanksgiving</option>
				    <option value="select_timeline">Timeline</option>
				    <option value="select_wives">Wives</option>
	              </select>
					
					
</p>
			    <p>Filter Resources by Submitter:</p>
			    <table width="408" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="193"><div align="center">
                        <label for="chuck">Chuck Coburn </label>
                        <input id="chuck" name="checkbox[]" type="checkbox" value="1" checked="checked"/>
                    </div></td>
                    <td width="215"><div align="center">
                        <label for="greg">Greg Smith </label>
                        <input id="greg" name="checkbox[]" type="checkbox" value="2" checked="checked"/>
                    </div></td>
                  </tr>
                  <tr>
                    <td><div align="center">
                        <label for="chris">Chris Jackson</label>
                        <input id="chris" name="checkbox[]" type="checkbox" value="3" checked="checked"/>
                    </div></td>
                    <td><div align="center">
                        <label for="ray">Ray Wall</label>
                        <input id="ray" name="checkbox[]" type="checkbox" value="4" checked="checked"/>
                    </div></td>
                  </tr>
                  <tr>
                    <td colspan="2"><div align="center">
                        <label for="guest">Guest Submitters </label>
                        <input id="guest" name="checkbox[]" type="checkbox" value="5" checked="checked"/>
                    </div>                      <div align="center">
                        <label for="resources"></label>
                                          </div></td>
                  </tr>
                </table>
			    <p>
			      <input type="submit" id="submit" name="submit" value="Filter Results">
				  </form>
				  
			    </p>
Search Resources:  
<form action="http://www.trinitypalatka.com/searchresults.html" id="cse-search-box">
			    <p><input type="hidden" name="cx" value="016442380590868967410:cesbaqqypzy" />
        <input type="hidden" name="cof" value="FORID:11" />
        <input type="hidden" name="ie" value="UTF-8" />
        <input type="text" name="q" size="20" />
        <input type="submit" name="sa" value="Search" /><br>
                </p>
          </form> </p>
<?php

if(isset($_POST['submit'])){
$category = $_POST['select'];
$done = implode(',', $_POST['checkbox']);
$author_num = $_POST['$done'];
{
if($author_num = 1):
$author = 'Chuck Coburn';
elseif($author_num = 2):
$author = 'Greg Smith';
elseif($author_num = 3):
$author = 'Chris Jackson';
elseif($author_num = 4):
$author = 'Ray Wall';
else:
$author = 'Guest';
endif;
}
$hour = time() + 3600;
setcookie('tbccategory', $category, $hour);
setcookie('tbcauthor', $category, $hour);
header("Location: onlineresources.php");
}

$query="SELECT * FROM Online_Resources $criteria";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
?>
<table class="sortable" border="1" cellspacing="2" cellpadding="2">
<tr>
<td><div align="center" class="20">Date</div></td>
<td><div align="center" class="20">Title</div></td>
<td><div align="center" class="20">Submitter</div></td>
<td><div align="center" class="20">Resource Type</div></td>
<td><div align="center" class="20">Category</div></td>
</tr>
<?php
while($i < $num) {

$f1=mysql_result($result,$i,"Date_Available");
$f2=mysql_result($result,$i,"Title");
$f3=mysql_result($result,$i,"Submitter");
$f4=mysql_result($result,$i,"Resource_Type");
$f5=mysql_result($result,$i,"Category");
?>
<tr>
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?></td>
<td><?php echo $f3; ?></td>
<td><?php echo $f4; ?></td>
<td><?php echo $f5; ?></td>
</tr>
<?php
$i++;
?>
<tfoot>
<tr>
<td colspan="5" align="center" bgcolor="#900011"><span class="style19">End of Results</span></td>
</tr>
</tfoot>
</table>          
          <p>&nbsp;          </p>
          <td width="104">&nbsp;</td>
		  <?php } ?>
		
      </tr>
    </table></td>
  </tr>
  <tr>
    <td background="Images/background-bottom2.png"><p align="center">&nbsp;
       Questions or comments reguarding our website? Email <a href="mailto:info@TrinityPalatka.com">info@trinitypalatka.com</a><br>
        Copyright &copy; 2010 Trinity Baptist Church of Silver Lake Drive - Website designed & maintained by <a href="http://www.christopherljackson.com">Christopher Jackson</a>.</p></td>
  </tr>
</table>

<!-- Start of StatCounter Code -->
<script type="text/javascript">
var sc_project=5669322; 
var sc_invisible=1; 
var sc_partition=65; 
var sc_click_stat=1; 
var sc_security="d1c56908"; 
</script>

<script type="text/javascript"
src="http://www.statcounter.com/counter/counter.js"></script><noscript><div
class="statcounter"><a title="custom counter"
href="http://www.statcounter.com/free_hit_counter.html"
target="_blank"><img class="statcounter"
src="http://c.statcounter.com/5669322/0/d1c56908/1/"
alt="custom counter" ></a></div></noscript>
<!-- End of StatCounter Code -->


</body>
</html>
Last edited by cjackson721 on Thu Sep 30, 2010 11:05 am, edited 2 times in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: php knowledge base search page

Post by requinix »

I, for one, am not going to bother looking at anything you posted until you put

Code: Select all

 tags around your code.

Edit your post, select all that PHP code, and click the "PHP Code" button.
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: php knowledge base search page

Post by DigitalMind »

Remove leading spaces and use setcookie before any output.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: php knowledge base search page

Post by twinedev »

FIRST THING: Edit your post and get your SQL connection data out of there (and now that is has been posted here, if you know how, go change your password on the server!!!!

Now, back to the issue:

If you are getting a white screen for the ob_start(), try seeing if you have access to your error logs to see what the error is.

In looking at the errors you are getting, the line count does not match up to the line numbers if I copy and paste your code to an editor, so it makes me wonder if they are not first. (when I remove the ob_start() chunk, they are even farther off).

Also, this is a good example of why separating the programming logic and the display into two sections (or files) is a good thing. Helps eliminate this issue and eliminate the need for the output buffering (ob_start).

While I think it auto dumps the OB at the end of a script, try specifically doing so with the following at the bottom:

Code: Select all

<?php ob_end_flush(); ?>

-Greg
cjackson721
Forum Newbie
Posts: 3
Joined: Thu Sep 30, 2010 6:43 am
Location: Palatka, Florida, USA

Re: php knowledge base search page

Post by cjackson721 »

Thanks guys for the quick replies.

tasairis
I made those corrections, sorry for missing that earlier.

DigitalMind
I have looked over the code and haven't seen any of the blank lines you were referring to... could you point me in the right direction to where you're seeing the blanks?

twinedev
I know that this is a newbie question for you, but... where do I go to look for the error logs?

I have tried using "ob_end_flush" in multiple places in the code. It seems that if I put it anywhere after the start of the table (line 94), then it gives the same errors pointed to anything from the html start tag to the php start tag (line 18) to the table start tag (line 94). If I try putting it above the start of the table (line 94), then it gives a blank page.

If I remove the "ob_end_flush", then it gives me a blank page... unless I also remove the "ob_start".

Based on my understanding of twinedev's and DigitalMind's suggestions (probably misunderstanding would be more accurate), I tried putting all of the php code (except for generating the result table - line 308) above the html start tag. When I tried this, I would always get a blank page (with or without "ob_start" and "ob_end_flush").

Thanks again, guys... I'll be back on this evening after work to take a crack at any further suggestions that ya'll have provided.
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: php knowledge base search page

Post by DigitalMind »

cjackson721 wrote: I have looked over the code and haven't seen any of the blank lines you were referring to... could you point me in the right direction to where you're seeing the blanks?
Removing blank lines is optional. Looks like that's not your case, but as i also said you should use setcookie() before any output. You're using setcookie() after some HTML code is sent.
setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace.
cjackson721
Forum Newbie
Posts: 3
Joined: Thu Sep 30, 2010 6:43 am
Location: Palatka, Florida, USA

Re: php knowledge base search page

Post by cjackson721 »

DigitalMind wrote: you should use setcookie() before any output. You're using setcookie() after some HTML code is sent.
Thanks for the suggestion. I just tried putting the "setcookie" before all the html and I got a blank page when I included the "ob_start" and also when I removed the "ob_start" from before the "setcookie."
Post Reply