通过HTML表单访问PHP文件



>我正在我的网站上工作,该网站具有不同的选项卡(主页,联系人等(。现在,在其中一个选项卡中,我正在使用登录表单,在此表单中,我只是在验证一个固定用户(不使用数据库(,这将从verification.php代码中理解。

下面是调用verification.php文件的.html文件代码的一部分

<div id="loginn" class="loginForm">
<form action="verfication.php" method="post">
<div class="ll">
<img src="image/avatar2.png">
</div>
<label for="name"><b>Username</b></label><br>
<input type="text" name="uname" required><br>
<label for="psw"><b>Password</b></label><br>
<input type="password" name="psw" required><br>
<button type="submit">Login</button>
</form>
</div>

下面是我的verification.php文件,由我保存在www目录中,其中存储了所有html,css,js文件

<!DOCTTYPE html>
<html>
<body>
<?php
if(isset($_POST['uname']) and isset($_POST['psw']))
{
$name=$_POST['uname'];
$pass=$_POST['psw'];
if ( $name == "rrrr"  and  $pass="ravina@6543" )
{
?>
<script type="text/javascript">document.getElementById('veri').style.display="block";</script>
<script type="text/javascript">document.getElementById('loginn').style.display="none";</script>
<?php}
}
?>           
</body>
</html>

现在的问题是,当我单击登录按钮时,html部分没有任何反应。我的意思是,我的PHP文件无法从我的HTML部分访问,所以任何人都可以帮助我解决这些问题吗?

我认为语法中存在错误:首先<!DOCTTYPE html>中有一个额外的"T",其次在启动php脚本后有一个大括号:<?php},只需添加一个空格即可解决您的问题。

您的 html 代码中还有一个关于 php 文件名称的拼写错误verification.php.

<!DOCTYPE html>
<html>
<body>
<?php
if(isset($_POST['uname']) and isset($_POST['psw']))
{
$name=$_POST['uname'];
$pass=$_POST['psw'];
if ( $name == "rrrr"  and  $pass="ravina@6543" )
{
?>
<script type="text/javascript">document.getElementById('veri').style.display="block";</script>
<script type="text/javascript">document.getElementById('loginn').style.display="none";</script>
<?php }
}
?>          
</body>
</html>

在您的验证.php中,您可以仅使用echo来检查成功/不

成功
<!DOCTYPE html>
<html>
<body>
<?php
if(isset($_POST['uname']) and isset($_POST['psw']))
{
$name=$_POST['uname'];
$pass=$_POST['psw'];
if ( $name == "rrrr"  and  $pass="ravina@6543" )
{
echo "success~~";
} else {
echo "failed!!";
}
}
?>          
</body>
</html>

这不是如何使用PHP,HTML和javascript。你应该从学习HTTP的工作原理开始,然后是HTML,然后是JavaScript,最后是PHP。

首先,您应该在html表单中正确编写php文件的名称,即验证.php 验证.php文件从 DOCTTYPE html 中删除一个 T,并在 ?php{ 这一行中在 php 和 { 之间给出一个空格。

最新更新