[RESOLVED] Why extra </p> tag?
Results 1 to 7 of 7

Thread: [RESOLVED] Why extra </p> tag?

  1. #1
    Join Date
    Jan 2017
    Michigan / United States

    resolved [RESOLVED] Why extra </p> tag?

    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> ↩

    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:
    PHP Code:
    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 >
                        <td style="width:20%" ><img width="96" height="96"       src="store_admin/inventory_images/'
    .$id.'.jpg" alt="image"/></td>
                        <td style="width:80%" >'
                        <a href=" product.php?id='
    .$id.'"> View Product Details</a>
    } else {
    $dynamiclist 'We have no products listed in your store yet';

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

    HTML Code:
    <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>
    					<a href=" product.php?id=6"> View Product Details</a>
    Please notify me if the complete html code is needed for your review.

    p tag.png

  2. #2
    Senior Member Derokorian's Avatar
    Join Date
    Apr 2011
    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.
    Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
    I'd rather be a comma, then a full stop.
    User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning

  3. #3
    Join Date
    Jan 2017
    Michigan / United States

    Talking extra </p> tag solved

    I was outputting the dynamic list by using
    HTML Code:
    <p> <?php echo $dynamiclist; ?> </p>.

    I changed to
    HTML Code:
    <?php echo $dynamiclist; ?>
    omitting the <p> & </p> tags resolved the issue.

    Thank you for having a look at this for me.

  4. #4
    Join Date
    Jan 2017
    Michigan / United States
    By the way does anyone know of a validation tool that will handle php & html combinations?

  5. #5
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Accelerating Windows at 9.81 m/s....
    Quote Originally Posted by New_PHP_Guy View Post
    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/tutoria...ntax-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/).

    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  6. #6
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    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.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  7. #7
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    General Systems Vehicle "Running Gear"
    "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).
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts