I have a .php page that I am trying to validate,
using w3.org Nu Html Checker.
When I view page source and copy & paste in validator I get the following:
Error: No p element in scope but a p end tag seen.
From line 102, column 13; to line 102, column 16
</table> </p> &#8617;

It occurs in both Chrome & FireFox.

Is it possibly because of the else {' '} clause on the end of the php code block?
This is right where the php would stop rendering the tables on the page.
I have tried commenting out the else clause, saving the file and refreshing the browser and the tag still appears.

If I try to validate by copy & paste from notepad++ I get the following:

Error: Saw <?. Probable cause: Attempt to use an XML processing instruction in HTML. (XML processing instructions are not supported in HTML.)

This is the php code block:

 
include "conn_to_mysqli.php";

//this block grabs the list for viewing
$dynamiclist = '';
$sql = mysqli_query($con, 'SELECT * FROM `products` ORDER BY `date_added` ASC LIMIT 6');
$product_count = mysqli_num_rows($sql);
if ($product_count > 0) {
    while ($row = mysqli_fetch_array($sql)) {
        $id = $row['id'];
        $product_name = $row['product_name'];
		$price = $row ['price'];
		$details = $row ['details'];
        $dynamiclist .= 
			'<table >
				<tr>
					<td style="width:20%" ><img width="96" height="96"       src="store_admin/inventory_images/'.$id.'.jpg" alt="image"/></td>
					<td style="width:80%" >'.$product_name.'<br>
					$'.$price.'<br>
					<a href=" product.php?id='.$id.'"> View Product Details</a>
					</td>
				</tr>
			</table>';
		}
} else {
    $dynamiclist = 'We have no products listed in your store yet';
}

The mystery </p> tag occurs right after the </table> tag.

<td style="width:20%" ><img width="96" height="96"  src="store_admin/inventory_images/6.jpg" alt="image"/></td>
					<td style="width:80%" >cruzer lite pink<br>
					$299.99<br>
					<a href=" product.php?id=6"> View Product Details</a>
					</td>
				</tr>
			</table></p>

Please notify me if the complete html code is needed for your review.

[ATTACH]5453[/ATTACH]

p tag.png

    What do you do with the $dynamiclist variable? At some point you have to output it I imagine. I'm wondering if its being output into <p></p> as that would be what you want in case the $dynamiclist is the string in the else clause.

      I was outputting the dynamic list by using

      <p> <?php echo $dynamiclist; ?> </p>.

      .

      I changed to

      <?php echo $dynamiclist; ?>

      omitting the <p> & </p> tags resolved the issue.

      Thank you for having a look at this for me.

        By the way does anyone know of a validation tool that will handle php & html combinations?

          New_PHP_Guy;11061525 wrote:

          By the way does anyone know of a validation tool that will handle php & html combinations?

          What would be the purpose of that? The W3C validator validates rendered web pages, which will never contain php. The point is to make sure that a standards-conformant UserAgent (such as, I dunno, some browser or another but not some others 😉 ) will render your page in a way that conforms to the spec, which should mean, more or less, the same for everyone, blah blah. (I'm not sure how much we trust it, but I don't think it's quite as difficult these days as it was 10 years ago unless the PHB insists that you continue to support IE < 9, etc., etc.)

          As far as PHP --- most of us validate PHP by running it and checking for errors. There's an entire book's worth of talk about that. What does your setup look like? I suppose I could understand this question better if you have only one server, the production/WWW box, write your code in Notepad/Pico/Kate/Vim and then put it up on the only server via FTP or some similar technology ... such that you can't test until it's live on the site.

          If that's the case, fix this situation ASAP or find another place to work if at all possible ... we want you to live a long & happy life ;-) (I have one site without a proper sandbox and it's absolutely killing me ...)

          If you want to "validate" PHP in some other way, you should get an IDE with a syntax checker (most all of them have one, and you should be using one whenever possible & sensible anyway), or run "php -l foo.php" in a command-line context (with a properly configured php cli, of course). If that's too much work, there are online resources that do the same thing, such as http://www.meandeviation.com/tutorials/learnphp/php-syntax-check/v5-3/syntax-check.php (for v5.3).

          If you're brave, generally positive-thinking and don't invest too much of your self-worth in your code, you should also check out PHP Mess Detector (https://phpmd.org/).

          HTH,

            IIRC, the PHPStorm IDE was pretty good at the combined syntax checking, though I'm not sure how smart it was when portions of the HTML were in conditional blocks -- which would be tricky for any validator, which is another good reason to segregate the PHP and the HTML as much as possible. 🙂

              "Given a PHP program that (allegedly) produces HTML output, verify that the HTML that it produces is valid."
              Well, there's no validation tool that can do that (see Rice's theorem). Not without running it for all possible inputs and checking all of its possible outputs.

              As NogDog suggests, separating the two languages so that the programming doesn't get in the way of the markup makes it easier to check the latter (it would have some insulation from the consequences of Rice's theorem, since HTML isn't a programming language).

                Write a Reply...