Jump to content

footer disappearing


barrowvian

Recommended Posts

could someone take a quick look at this please; i know the codes a bit messy at the moment  :P

<?php include("includes/header.php"); ?>

<div id="main">
    	<div class="container">
        
        	<div id="header">
            
            	<ul id="menu">
                	<li><a href="/ads/index.php">Homepage</a></li>
                	<li><a href="/ads/search.php" class="active">Search</a></li>
                	<li><a href="/ads/faq.php">FAQ</a></li>
                	<li><a href="/ads/blog.php">Blog</a></li>
                	<li><a href="/ads/contact.php">Contact</a></li>
                </ul>
                
                <ul id="menu2" name="menu2">
			<form action="search.php" method="GET">
			  <input type="text" name="searchterms" size="20" />
			  <input type="submit" 			value="Search"></form>
			</ul>
                
            	<div id="logo"></div>
            
            </div>
            
            <div id="block_featured" class="block">
			<img src="images/ribbon_featured.png" class="ribbon" alt="Featured Project"/>
       	    <div class="block_inside">
                
                	<div class="text_block">
                    
                    <form action="search.php" method="GET">

				<b>Enter Search Term:</b> <input type="text" name="searchterms" size="30">

				<input type="submit" value="Search">

				</form><br />
                    

                    <?php
				$error = array(); // creates an array for the errros to be stored.
				$results = array();

				if (isset($_GET['searchterms'])) {

					$searchTerms = trim($_GET['searchterms']); // trims the white space from searchterms
   						$searchTerms = strip_tags($searchTerms); // remove any html/javascript.

					if (strlen($searchTerms) < 3) {
						echo "Search terms must be longer than 3 characters.";
						exit;
   						}else {
      						$searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection.
   						}

					if (strlen($searchTerms) > 50) {
						echo "Search terms must be shorter than 50 characters.";
						exit;
   						}

					// If there are no errors, lets get the search going.
   						if (count($error) < 1) {

					//sql fulltext statement against words/phrase user enters
					$sql = "SELECT *, MATCH(company_name, search_data) AGAINST('%$_GET[searchterms]%') AS score FROM adverts WHERE MATCH(company_name, search_data) AGAINST('%$_GET[searchterms]%') LIMIT 0, 500";
									   
					$result = mysql_query($sql);
					$row = mysql_fetch_assoc($result);
					$max_score = 0;
					$data = array();									   

					//display an error if the query returns no results
					if (mysql_num_rows($result) < 1 && strlen($searchTerms) > 3 && strlen($searchTerms) < 50) {
         					echo "No results found for <strong>{$searchTerms}</strong>.";
						exit;
      					}

					echo "Your search: <strong>{$searchTerms}</strong> returned; <br /><br />";
					echo '<table width="100%" table border="0" style="border-width: 1px; border-color:#000000;
border-style: solid;" cellspacing="0" cellpadding="2">';
                    	echo '<tr>';


					echo "<td width=\"15%\" style=\"background-color: #00C\" style=\"color:white\">" . "<font color=\"white\"><strong>Relevance</font></strong>" . " " . "</td>"

					. "<td width=\"20%\" style=\"background-color: #00C\">" . "<font color=\"white\"><strong>Logo</font></strong>" . " " . "</td>"

					. "<td width=\"35%\" style=\"background-color: #00C\">" . "<font color=\"white\"><strong>Company</font></strong>" . " " . "</td>"

					. "<td width=\"30%\" style=\"background-color: #00C\">" . "<font color=\"white\"><strong>Link</font></strong>" . " " . "</td>";

					echo '</tr>';

					do {

					// results are already based upon relevance. this turns relevance into a %
					if($row['score'] > $max_score){ 
						$max_score = $row['score']; } //we can assume on the first run this wil be the max score.



				echo '<tr>';
                    
				echo "<td style=\"background-color: #e1e1e1\">" . @number_format(($row['score']/$max_score)*100,0)."%" . " " . "</td>"

				. "<td style=\"background-color: #e1e1e1\">" . $row['image_link'] . " " . "</td>"

				. "<td style=\"background-color: #e1e1e1\">" . $row['company_name'] . " " . "</td>"




                    	 . "<td style=\"background-color: #e1e1e1\">" . $row['company_link'] . "<br />" . "</td>";
                    
				echo '</tr>';

				}while($row = mysql_fetch_assoc($result));


					}


				}

echo '</table>';



			?>


                





   	          </div>
                    
              </div>
            </div>
            

        
        </div>
    </div>



<?php include("includes/footer.php"); ?>

 

Basically, when the page is called up the footer appears as normal, and when there is a valid search (with results) the footer is there as normal. But is I enter whilst the field is blank, or if i enter a field over 50 characters or a keyword that doesnt exist in the database then when the page is reloaded the footer is missing :/ can anyone see a way to correct this? thanks

Link to comment
https://forums.phpfreaks.com/topic/200934-footer-disappearing/
Share on other sites

Are the five </div> just before the footer gone too in the source of the page this creates when it does this?

 

If so, you need to take a look at the error checking. Your codes puking after finding nothing if it doesn't exist (Same reason for if searching a blank field). The 50 character lengths, some setting my guess on that... don't really know. 

 

Anyways what seems to be happening is that instead of breaking of exiting the code or skipping the code if it's blank or not found... it seems to try to execute it and then just stop processing spitting out everything up to that point then stopping suddenly. Try throwing some random echos in there just to see if it makes it where it shouldn't and where it should... and to see where it's stopping at. At quick glance I don't see anything sticking out at me though.

 

EDIT:  Try using exit(); instead of exit;

Link to comment
https://forums.phpfreaks.com/topic/200934-footer-disappearing/#findComment-1054288
Share on other sites

I tried switch to exit(); but no luck. Then realised about testing with echoes etc and found that this problem is only occurring when the exit(); has been applied. If I remove them then the footer appears but Im now left with the basic outline of the empty table upon each error so just need to sort out where to stop the code now.

Link to comment
https://forums.phpfreaks.com/topic/200934-footer-disappearing/#findComment-1054294
Share on other sites

Solved it :D it was actually quite easy when going through it section by section. I simply implemented a flag variable and checked if it was ok or not like so;

<?php include("includes/header.php"); ?>

<div id="main">
    	<div class="container">
        
        	<div id="header">
            
            	<ul id="menu">
                	<li><a href="/ads/index.php">Homepage</a></li>
                	<li><a href="/ads/search.php" class="active">Search</a></li>
                	<li><a href="/ads/faq.php">FAQ</a></li>
                	<li><a href="/ads/blog.php">Blog</a></li>
                	<li><a href="/ads/contact.php">Contact</a></li>
                </ul>
                
                <ul id="menu2" name="menu2">
			<form action="search.php" method="GET">
			  <input type="text" name="searchterms" size="20" />
			  <input type="submit" 			value="Search"></form>
			</ul>
                
            	<div id="logo"></div>
            
            </div>
            
            <div id="block_featured" class="block">
			<img src="images/ribbon_featured.png" class="ribbon" alt="Featured Project"/>
       	    <div class="block_inside">
                
                	<div class="text_block">
                    
                    <form action="search.php" method="GET">

				<b>Enter Search Term:</b> <input type="text" name="searchterms" size="30">

				<input type="submit" value="Search">

				</form><br />
                    

                    <?php
				$flag = "OK"; // creates an array for the errros to be stored.

				if (isset($_GET['searchterms'])) {

					$searchTerms = trim($_GET['searchterms']); // trims the white space from searchterms
   						$searchTerms = strip_tags($searchTerms); // remove any html/javascript.

					if (strlen($searchTerms) < 3) {
						echo "Search terms must be longer than 3 characters.";
						$flag = "NOTOK";
   						}else {
      						$searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection.
   						}

					if (strlen($searchTerms) > 50) {
						echo "Search terms must be shorter than 50 characters.";
						$flag = "NOTOK";
   						}

					// If there are no errors, lets get the search going.
   						if ($flag =="OK"){

					//sql fulltext statement against words/phrase user enters
					$sql = "SELECT *, MATCH(company_name, search_data) AGAINST('%$_GET[searchterms]%') AS score FROM adverts WHERE MATCH(company_name, search_data) AGAINST('%$_GET[searchterms]%') LIMIT 0, 500";
									   
					$result = mysql_query($sql);

					//display an error if the query returns no results
					if (mysql_num_rows($result) < 1 && strlen($searchTerms) > 3 && strlen($searchTerms) < 50) {
         					echo "No results found for <strong>{$searchTerms}</strong>.";
						$flag = "NOTOK";
      					}

					if ($flag =="OK"){
					$row = mysql_fetch_assoc($result);
					$max_score = 0;
					$data = array();									   

					echo "Your search: <strong>{$searchTerms}</strong> returned; <br /><br />";
					echo '<table width="100%" table border="0" style="border-width: 1px; border-color:#000000;
border-style: solid;" cellspacing="0" cellpadding="2">';
                    	echo '<tr>';


					echo "<td width=\"15%\" style=\"background-color: #00C\" style=\"color:white\">" . "<font color=\"white\"><strong>Relevance</font></strong>" . " " . "</td>"

					. "<td width=\"20%\" style=\"background-color: #00C\">" . "<font color=\"white\"><strong>Logo</font></strong>" . " " . "</td>"

					. "<td width=\"35%\" style=\"background-color: #00C\">" . "<font color=\"white\"><strong>Company</font></strong>" . " " . "</td>"

					. "<td width=\"30%\" style=\"background-color: #00C\">" . "<font color=\"white\"><strong>Link</font></strong>" . " " . "</td>";

					echo '</tr>';

					do {

					// results are already based upon relevance. this turns relevance into a %
					if($row['score'] > $max_score){ 
						$max_score = $row['score']; } //we can assume on the first run this wil be the max score.



				echo '<tr>';
                    
				echo "<td style=\"background-color: #e1e1e1\">" . @number_format(($row['score']/$max_score)*100,0)."%" . " " . "</td>"

				. "<td style=\"background-color: #e1e1e1\">" . $row['image_link'] . " " . "</td>"

				. "<td style=\"background-color: #e1e1e1\">" . $row['company_name'] . " " . "</td>"




                    	 . "<td style=\"background-color: #e1e1e1\">" . $row['company_link'] . "<br />" . "</td>";
                    
				echo '</tr>';

				}while($row = mysql_fetch_assoc($result));


					}

					}
				}

echo '</table>';



			?>


                





   	          </div>
                    
              </div>
            </div>
            

        
        </div>
    </div>



<?php include("includes/footer.php"); ?>

 

Link to comment
https://forums.phpfreaks.com/topic/200934-footer-disappearing/#findComment-1054302
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.