当我在浏览器中加载页面时,我的 </form> 标签消失了,这导致我的表单无法正常工作,有什么想法吗?

My </form> tag disappears when I load the page in a browser, this results in my form not working, any ideas why?

当我在浏览器中加载页面时,我的标签消失了,这导致我的表单无法正常工作,有什么想法吗?我尝试了不同的浏览器,但得到了相同的结果。

<?php 

session_start();

if(!isset($_SESSION["username"])){

header("location: login/loginform.php");

 }else{

echo "Du är inloggad som " . $_SESSION["username"]; 
}

?>
<html>

<head

<meta charset="utf-8">

</head> 

<body

<form action="registerProduct.php" method="post">
    Namn: <input type="text" name="prodName"><br>
    Artikelnummer: <input type="text" name="prodNamenr"><br>
    Pris: <input type="text" name="prodPrice"><br>
    Bildlänk: <input type="text" name="prodImg"><br>
    Lagerstatus: <input type="text" name="prodStatus"><br>
    Beskrivning: <input type="text" name="prodDescrip"><br>
    <input type="submit" value="submit">

</form>

</body> 
</html>

您必须关闭 <head><body> 标签!

改变

  <body and <head

 <body> and <head>

您必须使用有效的标记:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title>An XHTML 1.0 Strict standard template</title>
    <meta http-equiv="content-type" 
        content="text/html;charset=utf-8" />
</head>

<body>

     <form action="registerProduct.php" method="post">
          Namn: <input type="text" name="prodName"><br>
          Artikelnummer: <input type="text" name="prodNamenr"><br>
          Pris: <input type="text" name="prodPrice"><br>
          Bildlänk: <input type="text" name="prodImg"><br>
          Lagerstatus: <input type="text" name="prodStatus"><br>
          Beskrivning: <input type="text" name="prodDescrip"><br>
         <input type="submit" value="submit">
     </form>

</body>
</html>

还要确保使用 exit after header 是一个好习惯,因为 php 脚本在重定向后不会立即停止执行。

<?php 

session_start();

if(!isset($_SESSION["username"])){

header("location: login/loginform.php");exit;

 }else{
//Note that printing anything before <html> tag will produce invalid markup 
echo "Du är inloggad som " . $_SESSION["username"];
}

?>