doutao5419
doutao5419
2016-08-16 22:18

在localhost中执行代码时,php文件中的部分html文件不会出现

已采纳

I'm creating a regitration page which includes php,html and css in bootstrap.Here is my php file.

<?php include "header.php"; ?>
<html>

<head></head>

<body>
  <!--content-->
  <div class=" container">
    <div class=" register">
      <h1>Register</h1>

      <?php if(isset($_GET[ 'error'])) { echo '<font color="red">'.$_GET[ 'error']. '</font>'; echo '<br><br>'; } if(isset($_GET[ 'ok'])) { echo '<font color="blue">You are successfully Registered..</font>'; echo '<br><br>'; } ?>


      <form action="process_register1.php" method="POST">
    </div>
    <div class="col-md-6 register-bottom-grid">
      <h3>Personal infomation</h3>
      <div>
        <span>Full Name</span>
        <input type="text" size="30" maxlength="30" name='fnm'>
      </div>
      <div>
        <span>Username</span>
        <input type="text" size="30" maxlength="30" name='unm'>
      </div>
      <div>
        <span>Password</span>
        <input type='password' name='pwd' size="30">
      </div>
      <div>
        <span> Confirm password</span>
        <input type='password' name='cpwd' size="30">
      </div>
      <div>
        <span> Gender</span>
        <input type="radio" value="Female" name="gender" id='f'>Female
        <input type="radio" value="Male" name="gender" id='m'>Male
      </div>
      <div>
        <span>E-mail address</span>
        <input type='mail' name='mail' size="30">
      </div>
      <div>
        <span> No contact</span>
        <input type="text" name='contact' size="30">
      </div>
      <div>
        <span> City</span>
        <select style="width: 195px;" name="city">

          <option>Tirana</option>
          <option>Korca</option>
          <option>Vlora</option>
          <option>Kavaja</option>



        </select>
      </div>


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


    </div>

    <div class="clearfix"></div>
    </form>
  </div>
  </div>

</body>

</html>

Here is my header.php file:

<?php session_start(); require( 'config.php'); ?>
<!DOCTYPE html>
<html>

<head>
  <title>Online Shopping</title>
  <link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
  <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
  <script src="js/jquery.min.js"></script>
  <!-- Custom Theme files -->
  <!--theme-style-->
  <link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
  <!--//theme-style-->
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="keywords" content="New Store Responsive web template, Bootstrap Web Templates, Flat Web Templates, Andriod Compatible web template, 
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyErricsson, Motorola web design" />
  <script type="application/x-javascript">
    addEventListener("load", function() {
      setTimeout(hideURLbar, 0);
    }, false);

    function hideURLbar() {
      window.scrollTo(0, 1);
    }
  </script>
  <!--fonts-->
  <link href='http://fonts.googleapis.com/css?family=Lato:100,300,400,700,900' rel='stylesheet' type='text/css'>
  <link href='http://fonts.googleapis.com/css?family=Roboto:400,100,300,500,700,900' rel='stylesheet' type='text/css'>
  <!--//fonts-->
  <!-- start menu -->
  <link href="css/memenu.css" rel="stylesheet" type="text/css" media="all" />
  <script type="text/javascript" src="js/memenu.js"></script>
  <script>
    $(document).ready(function() {
      $(".memenu").memenu();
    });
  </script>
  <script src="js/simpleCart.min.js">
  </script>
</head>

<body>
  <!--header-->
  <div class="header">
    <div class="header-top">
      <div class="container">
        <div class="search">
          <form>
            <input type="text" value="Search " onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Search';}">
            <input type="submit" value="Go">
          </form>
        </div>
        <div class="header-left">
          <?php if(isset($_SESSION[ 'status'])) { echo '<ul><li><a href="logout.php">Logout</a></li></ul>'; } else { echo '<ul>
                        <li ><a href="login1.php"  >Login</a></li>
                        <li><a  href="register.php"  >Register</a></li>

                    </ul>'; } ?>

          <div class="cart box_1">
            <a href="checkout.html">
              <h3> <div class="total">
                            <span class="simpleCart_total"></span> (<span id="simpleCart_quantity" class="simpleCart_quantity"></span> items)</div>
                            <img src="images/cart.png" alt=""/></h3>
            </a>
            <p><a href="javascript:;" class="simpleCart_empty">Empty Cart</a>
            </p>

          </div>
          <div class="clearfix"></div>
        </div>
        <div class="clearfix"></div>
      </div>
    </div>
    <div class="container">
      <div class="head-top">
        <div class="logo">
          <a href="index.html">
            <img src="images/logo.png" alt="">
          </a>
        </div>
        <div>
          <h1 class="title">Welcome 
                            <?php 
                                if(isset($_SESSION['status']))
                                {
                                    echo $_SESSION['unm']; 
                                }
                                else
                                {   
                                    echo 'Book Store';
                                }
                            ?>
                </div>
          <div class=" h_menu4">
                <ul class="memenu skyblue">
                      <li class="active grid"><a class="color8" href="index1.php">Home</a></li> 
                      <li><a class="color1" href="#">Categories</a>
                      <div class="mepanel">
                                                <div class="row">
                     
                                        <?php
                                    $query="select * from category ";
                                    $res=mysqli_query($conn,$query);
                                   
                                    while($row=mysqli_fetch_assoc($res))
                                    { 
                                      echo'         <div class="col1">
                                                      <div class="h_nav">
                                                        <ul>';
                                  
                                         echo '<li>
                                                <a href="subcat.php?cat='.$row['cat_id'].'&catnm='.$row["cat_nm"].'">'.$row["cat_nm"].'
                                                </a>
                                               </li>';

                                       
                                                
                                        
                                         }
                                                    echo'   </ul> 
                                                    </div>                            
                                              </div>';





                                            mysqli_close($conn);
                                          ?>

                        
                        
                                        
                    
                   
                                
                <li><a class="color6" href="contact.html">Contact Us</a></li>
              </ul> 
            </div>
                
                <div class="clearfix"> </div>
        </div>
        </div>

    </div>
    

The problem is when I try to open the files from localhost only the header of the page appears so this is the result:enter image description here How is it possible that the form doesnt appear?

</div>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • drzrdc1766788 drzrdc1766788 5年前

    I assume, that your header.php begins a proper html page with doctype, <html> etc... but after

    <?php include "header.php"; ?>
    

    you start your html file again:

    <html>
    <head></head>
    <body>
    

    Make sure your markup is valid!

    点赞 评论 复制链接分享
  • douque2016 douque2016 5年前

    So it looks like your header file isn't a header, it's a complete HTML document. It opens the document (<html>) and then closes it (</html>). So it makes sense that any HTML you put after including the header won't get rendered - the browser will render the header and assume the document is complete.

    Instead you header file should end where the markup for the header ends. Usually this is the opening tag for the container of your content.

    Then when you include the header file, it will contain all the markup up to where your content begins, and in your form's file you can put the code for the form and it'll get rendered next.

    In your case, try removing the </body> and </html> tags from the header file. That will likely work, though your markup will likely need to be updated to make the design coherent. Also, since those are being created by your header, remove the <html>, <head></head>, and <body> tags from your form's file.

    You can also create a footer file that you can include after your form content, and it will close the container and the body and html tags.

    Edit

    May have scrolled to the end of the first code block when I saw the </body></html>, so you can probably disregard the advice to remove them from the header file - they appear to be there only in my imagination. Removing the opening <html>, <body>, and <head> tags from the from file should do the trick however.

    点赞 评论 复制链接分享

相关推荐