简体   繁体   English

php的标头位置转到404

[英]header location for php going to 404

Working on a simple sign in page where the user enters the name and password. 在简单的登录页面上工作,用户在其中输入名称和密码。 Right now I just have it so when the user enters the usrname and password it should redirect to my success.html page where it will just print out <h2>successful login</h2> . 现在,我有了它,因此当用户输入usrname和密码时,它应该重定向到我的success.html页面,在该页面中,它会打印出<h2>successful login</h2> Whenever I try to click the log in button, I can see in my browser that it is catching the username and password but it shows a 404 page. 每当我尝试单击“登录”按钮时,我都会在浏览器中看到它正在捕获用户名和密码,但是会显示一个404页面。 Any help would be appreciated. 任何帮助,将不胜感激。 I will put my code down below for both of the files. 我会将我的代码放到两个文件的下方。

`home.html`

<head>
<title>Hangman Home Page</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="home.css">
</head>

<body>

<?php

   #not empty
    #atleast 6 characters long


    # array holds errors
    $errors = array[];

    # validation starts here

    if(count($errors) == 0){

        # redirect to the game page
        header('Location:success.html');
        exit();
    }


    ?>

<div class="header">
<div class="a">Hangman</div>
</div>
<div class="topnav">
</div>
<br>
<br>
<br>
<!--column start here -->
<div class="hi">
<table id="leader">
<tr>
<th><img src="crown.gif"></th>
</tr>
<tr>
<td>Leader Board</td>
</tr>
<tr>
<td>1st. John : 4 guess</td>
</tr>
<tr>
<td>2nd. Smith : 6 Guesses</td>
</tr>
<tr>
<td>3rd. Tom : 7 Guesses</td>
</tr>
<tr>
<td>4th. Allen : 8 Guesses</td>
</tr>
</table>
</div>
<!-- form start here -->
<br>
<br>


<div class="b">Think You Can Beat #1 ?</div>

<center><button onclick="document.getElementById('id01').style.display='block'" style="width:auto;">Play Now!!!</button></center>

<div id="id01" class="modal">
<form method="post" class="modal-content animate">
<div class="imgcontainer">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">&times;</span>
<img src="hang1.gif" alt="logo" class="avatar">
</div>


<div class="container">
</p>

<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>


<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>

<button type="submit" value="submit">Login</button>
</div>
</form>

<div class="container" style="background-color:#f1f1f1">
<button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">Cancel</button>
<span class="psw">Forgot <a href="#">password?</a></span>
</div>
   </form>
    </div>

    </body>

    </html>

 `success.html`
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" 
 content="width=device- 
   width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" 
    content="ie=edge">
    <title>Document</title>
    </head>
    <body>

<h2> Successful Connection!</h2>
</body>
</html>

First thing, Where is the doctype and html tag for home.html? 第一件事,home.html的doctype和html标记在哪里? And the next is that forms should contain an action attribute that should specify the location/page where the information should be sent to like 接下来是表单应包含一个动作属性,该属性应指定将信息发送到的位置/页面,例如
<form action="success.html" method="POST" class="modal-content animate"> if success.html and home.html are in the same directory. 如果success.html和home.html在同一目录中,则<form action="success.html" method="POST" class="modal-content animate">
action attribute takes empty strings if you want the form to be submitted to the same page as he form. 如果您希望表单与表单一起提交到同一页面,则action属性将使用空字符串。
Although it is not necessary but not specifying it creates unexpected problems sometimes. 尽管没有必要,但没有指定它有时会导致意外的问题。 Read more basics about forms at https://www.w3schools.com/html/html_forms.asp https://www.w3schools.com/html/html_forms.asp上阅读有关表单的更多基础知识。

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

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