简体   繁体   English

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

[英]Part of html file inside php file doesnt appear when executing the code in localhost

I'm creating a regitration page which includes php,html and css in bootstrap.Here is my php file. 我正在创建一个在bootstrap中包含php,html和css的注册页面。这是我的php文件。

<?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: 这是我的header.php文件:

 <?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: 问题是,当我尝试从本地主机打开文件时,仅页面标题出现,因此结果如下: 在此处输入图片说明 How is it possible that the form doesnt appear? 表格怎么不出现?

I assume, that your header.php begins a proper html page with doctype, <html> etc... but after 我认为,您的header.php以doctype, <html>等开始了正确的html页面,但是之后

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

you start your html file again: 您再次启动html文件:

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

Make sure your markup is valid! 确保您的标记有效!

So it looks like your header file isn't a header, it's a complete HTML document. 因此,看来您的标头文件不是标头,而是完整的HTML文档。 It opens the document ( <html> ) and then closes it ( </html> ). 它打开文档( <html> ),然后关闭它( </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. 因此,有意义的是您放置包含标头之后的任何HTML都不会被渲染-浏览器将呈现标头并假定文档是完整的。

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. 您可以尝试从头文件中删除</body></html>标签。 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. 另外,由于这些标题是由您的标题创建的,因此请从表单文件中删除<html><head></head><body>标记。

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. 您还可以创建一个页脚文件,可以在表单内容之后添加该页脚文件,它将关闭容器, bodyhtml标签。

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. 当我看到</body></html> ,可能已经滚动到了第一个代码块的末尾,因此您可能会忽略将其从头文件中删除的建议-它们似乎只是在我的想象中。 Removing the opening <html> , <body> , and <head> tags from the from file should do the trick however. 但是,从from文件中删除开头的<html><body><head>标记应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM