当我在浏览器中加载页面时,我的 </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 是一个好习惯,因为 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"];
}

?>