Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

w3 validator 1

Status
Not open for further replies.

dldl

Programmer
May 3, 2010
40
NZ
Hi;
I am implementing a search engin by php, and i alway to have a error massage when i validate my page by the W3 Validator, error massage as following, could any one help, thanks.

end tag for "div" omitted, but OMITTAG NO was specifiedQuery was empty

You may have neglected to close an element, or perhaps you meant to "self-close" an element, that is, ending it with "/>" instead of ">".



my code

Code:
<?php

   $rows = get_number_of_rows();

    function get_number_of_rows(){
       include("../condatabase.php");
       mysql_query("SET NAMES 'utf8' COLLATE 'utf8_general_ci'");
       $q=getsql("affair with teen");
       $result=mysql_query($q,$con)or die(mysql_error());
       $rows = mysql_num_rows($result); 
       return $rows;
    
    }

   function getsql($search_str){

     $sql = "SELECT DISTINCT COUNT(*) as occurences,id, subject, content FROM pinboard WHERE (";
		             
			while ( list ( $key,$val ) = each ( $search_str ) )
			{
		              if( $val!=' && strlen ( $val ) > 0 )
		              {
		              	$sql .= "((subject LIKE '%".$val."%' OR content LIKE '%".$val."%')) OR";
		              }
			}
			
                       	$sql=substr ( $sql,0, ( strLen ( $sql )-3 ) );//this will eat the last OR
			//$sql .= ") GROUP BY subject ORDER BY occurences DESC LIMIT 10";

                       $sql .= ") GROUP BY subject ORDER BY occurences DESC ";

       

                return $sql;

   }


?>



but when i direct assign value to $sql="SELECT DISTINCT COUNT(*) as occurences,id, subject, content FROM pinboard WHERE (((subject LIKE '%affair%' OR content LIKE '%affair%')) OR((subject LIKE '%teen%' OR content LIKE '%teen%'))) GROUP BY subject ORDER BY occurences DESC"

and validate my page by W3 validator, it has not report any error, pefect.

Could anyone tell me, why please.
 
Nothing in that code has anything to do with a div, nor does it have any HTML code tovalidate.

I would question how you are validating the page, as you should never be validating PHP source code like that, only the resultant HTML from it as only that is what the browser will see.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
vacunita is right.

also, from what you've provided, we can't possibly answer your question with any certainty.

however, I would suspect you are printing a closing div within a block of php code that only runs when $sql equals some. for example

Code:
<div>
  ...
  <?
    if (isset($rows))
    {
       echo rows;
       echo "</div>";
    }
  ?>

if your query does not return anything, it is null and isset() will return false. therefore, the </div> will never be printed.

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
I paste my website address to w3 to validate it, then it give me error massage.

And now i get the source code from right click on my page, and validate it on the W3, it passes, not problem at all.

So i just leave it like that.

Thanks for advice
 
The following is my source from my right click on my page, it has not problem when i validate it on W3.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Yourheadstone.com</title>
<style type="text/css">

* {padding:0; margin:0;}

body{
  padding:0;
  border:0;
  background-image:url(../images/bg_images/2.jpg);
  margin:0;
}

#container {
  width:1024px;
  height:1005px;
  margin:30px auto;
  background-image:url(../images/container_images/5.jpg);
  border-top: 7px solid #80B2E6;
  border-right: 5px solid #ADC2DA;
  border-bottom: 6px solid #ADC2DA;
  border-left: 5px solid #ADC2DA;
}

#headertop{
  width:1020px;
  height: 90px;
  color:#0066CC;
  font-size:70px;
  padding-left:200px;
  float:left;

}

.logo{
  margin-left:65px;
  margin-top:20px;
  font-style:italic;
}

a{
  color:#0066CC;
  text-decoration: none;

}
#headermiddle{
  width:1020px;
  height: 45px;
  float:left;
}

#headermiddle_left{
  width:600px;
  height: 45px;
  float:left;
}

#headermiddle_right{
  width:400px;
  height: 45px;
  float:left;

}

form{
  width: auto;
  height: 38px;
  text-align:center; 
  background-color:#000000;

}

input{
  line-height: 25px;
  font-size: 18px;
  height: 30px;
  width: 195px;;
 
}

#headerbottom{
  width:1020px;
  height: 45px;
  background-color:#0AC20A;
  float:left;
}

.pagenums{
  color:#0C14F7;

}

.page{
  color:#0C14F7;

}

.mypage{
  background-color:#A7A8B8;

}

img {
  border-style:none;
}


#leftcolumn{
  width:150px;
  height:560px;
  float:left;
}

#middlecolumn{
  border-top: 7px solid #0A0A0A;
  border-right: 5px solid #948F91;
  border-bottom: 6px solid #A89D9F;
  border-left: 5px solid #8C8587;
  padding:10px;
  width:720px;
  height:560px;
  float:left;
  background-color:#FFFFFF;
}



.submittime{
  color:#00010A;
  width:150px;
  height:20px;
  float:left;
}

#rightcolumn{
  width:100px;
  height:560px;
  float:left;
}



</style>
</head>
<body>

<div id="container">


<div id="headertop"> <a href="index.php"> <span class="logo">  your headstone</span> </a></div>


<div id="headermiddle">

<div id="headermiddle_left">
<a href="index.php"> <img src="../images/flower.gif" alt="image" /></a>
</div>

<div id="headermiddle_right">
<form action="../search_pinboard/search_pinboard_process.php" method="post">
<input type="text" name="search" value=""  size="30"/>
<input type="submit" value="search" />
</form>
</div>

</div>


<div id="headerbottom"> 
<div id="result">Total 2 images.<br /></div> page 1 of 1--    <a class="mypage" href='/search_pinboard/search_pinboard.php?pagenum=1'> 1 </a> 
</div>

<div id="leftcolumn"> </div>

<div id="middlecolumn"> 

<a href="../pinboard/pinboard_massage.php?id=3">i am testing</a><br />Only photo:Images of dead Melbourne son on stolen camera<br />
<br />
Royal lookalikes:Kate and Mary\\\\\\\\\\\\\\\'s double date for charity<br />
<br />
Lazy extreme:Wife\\\\\\\\\\\\\\\'s food spiked to make her stay-at-home mum<br />
<br />
Dead babysitter:Couple had drug-fuelled affair with teen help<br /><div class="submittime"></div><br /><br /><a href="../pinboard/pinboard_massage.php?id=2">job test me</a><br /><img src="../images/biggrin.gif" alt="image" />         <img src="../images/smile.gif" alt="image" />   Only photo:Images of dead Melbourne son on stolen cameraRoyal lookalikes:Kate and Mary\\\'s double date for charityLazy extreme:Wife\\\'s food spiked to make her stay-at-home mumDead babysitter:Couple had drug-fuelled affair with teen help<br /><div class="submittime"></div><br /><br />
</div>

<div id="rightcolumn"> </div>

</div>

</body>
</html>
 
Yes, your HTML is fine, with no errors. I'm guessing something along the lines of Geats suggestion. Something that gets output when the browser is not the expected one or something like that. I'd check it again and make a note of which line its complaining about.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Too strange!

If i direct to assign value to $q instead of ($q=getsql("affair with teen");), there is no error from W3 validator.

Example

$q="select * from pinboard";

or

$q="SELECT DISTINCT COUNT(*) as occurences,id, subject, content FROM pinboard WHERE (((subject LIKE '%affair%' OR content LIKE '%affair%')) OR((subject LIKE '%teen%' OR content LIKE '%teen%'))) GROUP BY subject ORDER BY occurences DESC";
 
and what happens if you assign null to $q and validate?

Code:
$q = null;

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
The following error massage from W3 Validator, after i assign null to $q.

Code:
end tag for "div" omitted, but OMITTAG NO was specified Query was empty


You may have neglected to close an element, or perhaps you meant to "self-close" an element, that is, ending it with "/>" instead of ">".
 
You have something either not being output or being output when it should not, when your query does not return results.

Any chance we could see the full code?

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Code:
getSql.php
/////////////
[CODE]


  function get_sql($string){

    include("stem.php");
    include("cleaner.php");

    function get_stemmer($string){
       $stemmer = new Stemmer;
       $stemmed_string = $stemmer->stem ( $string );
      return $stemmed_string;
    }

    $string=explode(" ",$string);
    $size=sizeof($string);
                
    $i=0;
    $stemmed_string="";
    while($i<$size){
       $word=get_stemmer($string[$i]);
       $stemmed_string .= " " . $word;
       $i++;
     }
                
	
    $clean_string = new jSearchString();
    $stemmed_string = $clean_string->parseString ( $stemmed_string );	

    //echo $stemmed_string . "<br />";
		
	
    $new_string = ';	
    foreach ( array_unique ( split ( " ",$stemmed_string ) ) as $array => $value )
    {
	if(strlen($value) >=2)
	{
                                
	   $new_string .= " " .$value.' ';
	}
    }

    //echo $new_string . "<br />";


    $new_string = substr ( $new_string,0, ( strLen ( $new_string ) -1 ) );

    //echo $new_string . "<br />";               
		
    if ( strlen ( $new_string ) > 3 )
		
    $split_stemmed = split ( " ",$new_string );

                                       		        

    $sql = "SELECT DISTINCT COUNT(*) as occurences,id, subject, content FROM pinboard WHERE (";
		             
			while ( list ( $key,$val ) = each ( $split_stemmed ) )
			{
		              if( $val!=' && strlen ( $val ) > 0 )
		              {
		              	$sql .= "((subject LIKE '%".$val."%' OR content LIKE '%".$val."%')) OR";
		              }
			}
			
                       	$sql=substr ( $sql,0, ( strLen ( $sql )-3 ) );//this will eat the last OR
			//$sql .= ") GROUP BY subject ORDER BY occurences DESC LIMIT 10";

                       $sql .= ") GROUP BY subject ORDER BY occurences DESC ";

       

                return $sql;


   }




////////////////////////////////////

index.php
///////////////////////////////////////

<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Yourheadstone.com</title>
<style type="text/css">

* {padding:0; margin:0;}

body{
padding:0;
border:0;
background-image:url(../images/bg_images/<?php $num=rand(1,2); $image=$num . ".jpg"; echo $image; ?>);
margin:0;
}

#container {
width:1024px;
height:1005px;
margin:30px auto;
background-image:url(../images/container_images/<?php $num=rand(4,6); $image=$num . ".jpg"; echo $image; ?>);
border-top: 7px solid #80B2E6;
border-right: 5px solid #ADC2DA;
border-bottom: 6px solid #ADC2DA;
border-left: 5px solid #ADC2DA;
}

#headertop{
width:1020px;
height: 90px;
color:#0066CC;
font-size:70px;
padding-left:200px;
float:left;

}

.logo{
margin-left:65px;
margin-top:20px;
font-style:italic;
}

a{
color:#0066CC;
text-decoration: none;

}
#headermiddle{
width:1020px;
height: 45px;
float:left;
}

#headermiddle_left{
width:600px;
height: 45px;
float:left;
}

#headermiddle_right{
width:400px;
height: 45px;
float:left;

}

form{
width: auto;
height: 38px;
text-align:center;
background-color:#000000;

}

input{
line-height: 25px;
font-size: 18px;
height: 30px;
width: 195px;;

}

#headerbottom{
width:1020px;
height: 45px;
background-color:#0AC20A;
float:left;
}

.pagenums{
color:#0C14F7;

}

.page{
color:#0C14F7;

}

.mypage{
background-color:#A7A8B8;

}

img {
border-style:none;
}


#leftcolumn{
width:150px;
height:560px;
float:left;
}

#middlecolumn{
border-top: 7px solid #0A0A0A;
border-right: 5px solid #948F91;
border-bottom: 6px solid #A89D9F;
border-left: 5px solid #8C8587;
padding:10px;
width:720px;
height:560px;
float:left;
background-color:#FFFFFF;
}



.submittime{
color:#00010A;
width:150px;
height:20px;
float:left;
}

#rightcolumn{
width:100px;
height:560px;
float:left;
}



</style>
</head>
<body>

<div id="container">


<div id="headertop"> <a href="index.php"> <span class="logo"> your headstone</span> </a></div>


<div id="headermiddle">

<div id="headermiddle_left">
<a href="index.php"> <img src="../images/flower.gif" alt="image" /></a>
</div>

<div id="headermiddle_right">
<form action="../search_pinboard/search_pinboard_process.php" method="post">
<input type="text" name="search" value="" size="30"/>
<input type="submit" value="search" />
</form>
</div>

</div>


<div id="headerbottom">
<?php
include("getSql.php");

function get_number_of_rows(){
include("../condatabase.php");
mysql_query("SET NAMES 'utf8' COLLATE 'utf8_general_ci'");

$searchStr=$_GET['searchStr'];
$q=get_sql($searchStr);

$result=mysql_query($q,$con)or die(mysql_error());

$rows = mysql_num_rows($result);
return $rows;

}


//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($_GET['pagenum'])))
{
$_GET['pagenum'] = 1;
}

$page_rows = 3;

$rows = get_number_of_rows();

if($rows==0){
echo ("<div id=\"no_result\">There are not result.....</div>");
exit;
}
else{
echo ("<div id=\"result\">Total " . $rows . " images." . "<br /></div>");

}

//This tells us the page number of our last page
$last = ceil($rows/$page_rows);

//this makes sure the page number isn't below one, or more than our maximum pages
if ($_GET['pagenum'] < 1)
{
$_GET['pagenum'] = 1;
}
else if ( $_GET['pagenum'] > $last)
{
$_GET['pagenum'] = $last;
}



function get_max(){
$page_rows = 3;
//This sets the range to display in our query
$max = " limit " .( $_GET['pagenum'] - 1) * $page_rows ."," .$page_rows;
return $max;
}

//echo ("<div class=\"pagenums\">");

// This shows the user what page they are on, and the total number of pages
echo " page " . $_GET['pagenum'] . " of " . $last . "-- ";


// First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.
if ( $_GET['pagenum'] == 1)
{
}
else
{
$previous = $_GET['pagenum']-1;
echo " <a class=\"page\" href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> Previous</a> ";
}


$pagenum=$_GET['pagenum'];
$start=1;
$check=$pagenum-3;
if($check<0)
$start=1;
else if($check==0)
$start=1;
else if($check>0)
$start=$pagenum-3;

// echo $start;

$end=$last;
$check=$last-$pagenum;
if($check==0)
$end=$last+1;
else if($check>3)
$end=$pagenum+4;
else if($check<3)
$end=$last+1;



//list all the page number

while($start<$end){
if($pagenum==$start)
echo " <a class=\"mypage\" href='{$_SERVER['PHP_SELF']}?pagenum=$start'> $start </a> ";
else
echo " <a class=\"page\" href='{$_SERVER['PHP_SELF']}?pagenum=$start'> $start </a> ";
$start++;
}


//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ( $_GET['pagenum'] == $last)
{
}
else {

$next = $_GET['pagenum']+1;
echo " <a class=\"page\" href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next page -</a> ";
}





?>

</div>

<div id="leftcolumn"> </div>

<div id="middlecolumn">

<?php

include("../condatabase.php");


//Callback function for preg_replace_callback below
function convert_for_html ($matches) {
$regex[0] = "[";
$regex[1] = "]";
$replace[0] = "[";
$replace[1] = "]";
ksort($regex);
ksort($replace);
$treated = str_replace($regex, $replace, $matches[1]);
$output = '<table class="code"><tr><td>Code:</td></tr><tr><td class="code_box">' . $treated . '</td></tr></table>';

return $output;
}


include("convert_data.php");
global $con;


list_massages();



mysql_close($con);

function list_massages(){
include("../condatabase.php");
$max=get_max();


$searchStr=$_GET['searchStr'];
$q=get_sql($searchStr);
$q=$_SESSION['sql']. $max;



$result=mysql_query($q,$con)or die(mysql_error());


while($row = mysql_fetch_array($result)){
$subject=$row['subject'];
$content=$row['content'];
$id=$row['id'];


$submittime=$row['submittime'];

echo "<a href=\"../pinboard/pinboard_massage.php?id=$id\">";
$subject=output_post($subject);
echo $subject;
echo "</a>";

echo "<br />";
$content=output_post($content);
echo $content;

echo "<br />";

echo "<div class=\"submittime\">";
echo $submittime;
echo "</div>";

echo "<br /><br />";

}


}



function display_username($userid){
include("../condatabase.php");
$q="select * from user where id='$userid'";
$result=mysql_query($q,$con)or die(mysql_error());


while($row = mysql_fetch_array($result)){
$username=$row['username'];
echo $username;
}

}


?>

</div>

<div id="rightcolumn"> </div>

</div>

</body>
</html>


[/CODE]
 
nothing stands out in this code. can you post convert_data.php? also, where in the code can you set $q = null to get the error?

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Code:
 convert_data.php

<?php


function output_post ($post) {
//Make safe any html
$post_no_html = htmlspecialchars($post);

//Make sure there is no whitespace at the end of the message
//It's conceivable that the user will start their message with whitespace
$post_abridged = chop($post_no_html);

        //Convert code tags
        $code_treated = preg_replace_callback(
                        "/\[code\](.+?)\[\/code\]/s",
                   "convert_for_html",
                   $post_abridged);
//Arrays for the bbCode replacements
        $bbcode_regex = array(0 => '/\[b\](.+?)\[\/b\]/s',
                                                1 => '/\[i\](.+?)\[\/i\]/s',
                                                2 => '/\[u\](.+?)\[\/u\]/s',
                                                3 => '/\[quote\](.+?)\[\/quote\]/s',
                                                4 => '/\[quote\=(.+?)](.+?)\[\/quote\]/s',
                                                5 => '/\[url\](.+?)\[\/url\]/s',
                                                6 => '/\[url\=(.+?)\](.+?)\[\/url\]/s',
                                                7 => '/\[img][/img](.+?)\[\/img\]/s',
                                                8 => '/\[color\=(.+?)\](.+?)\[\/color\]/s',
                                                9 => '/\[size\=(.+?)\](.+?)\[\/size\]/s',
                                                10=>'/\:honorhim:/s',
                                                11=>'/\:cool:/s',
                                                12=>'/\:tongue:/s',
                                                13=>'/\:smile:/s',
                                                14=>'/\:zall_coho:/s',
                                                15=>'/\:biggrin:/s',
                                                16=>'/\:cool:/s',
                                                17=>'/\:razz:/s'
                                                 );

        $bbcode_replace = array(0 => '<b>$1</b>',
                                                1 => '<i>$1</i>',
                                                2 => '<u>$1</u>',
                                                3 => '<table class="quote"><tr><td>Quote:</td></tr><tr><td class="quote_box">$1</td></tr></table>',
                                                4 => '<table class="quote"><tr><td>$1 said:</td></tr><tr><td class="quote_box">$2</td></tr></table>',
                                                5 => '<a href="$1">$1</a>',
                                                6 => '<a href="$1">$2</a>',
                                                7 => '<img src="$1" alt="User submitted image" title="User submitted image"/>',
                                                8 => '<span style="color:$1">$2</span>',
                                                9 => '<span style="font-size:$1">$2</span>',
                                                10=> '<img src="../images/honorhim.gif" alt="image" />',
                                                11=>'<img src="../images/cool.gif" alt="image" />',
                                                12=>'<img src="../images/tongue.gif" alt="image" />',
                                                13=>'<img src="../images/smile.gif" alt="image" />',
                                                14=>'<img src="../images/zall_coho.gif" alt="image" />',
                                                15=>'<img src="../images/biggrin.gif" alt="image" />',
                                                16=>'<img src="../images/cool.gif" alt="image" />',
                                                17=>'<img src="../images/razz.gif" alt="image" />'
                                                 );

        ksort($bbcode_regex);
        ksort($bbcode_replace);

        //preg_replace to convert all remaining bbCode tags
        $post_bbcode_treated = preg_replace($bbcode_regex, $bbcode_replace, $code_treated);
//Convert new lines to <br />
        $post_with_br = nl2br($post_bbcode_treated);


        return $post_with_br;
}
?>
 
>>>> where in the code can you set $q = null to get the error?<<<

From index.php
Code:
    include("getSql.php");
    function get_number_of_rows(){
       include("../condatabase.php");
       $searchStr=$_GET['searchStr'];       
       $q=get_sql($searchStr);           
       $result=mysql_query($q,$con)or die(mysql_error());          
       $rows = mysql_num_rows($result);        
       return $rows;       
     }


also
 
  function list_massages()
  {    
      include("../condatabase.php");    
      $max=get_max();    
      $searchStr=$_GET['searchStr'];   
      $q=get_sql($searchStr);    
      $q=$_SESSION['sql']. $max;
      ....
  }
 
not sure. comment out blocks of code to narrow down from where the error is coming. that's all I can suggest :/

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Thanks for your time anywhere , it is so hard to find the problem out.
 
actually, you may be getting a fatal error. Such error would cause subsequent HTML not to be output. put this at the beginning of your main php file and see if any errors are returned.

Code:
 ini_set('display_errors', true);
 error_reporting(E_ALL);

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top