简体   繁体   English

通过HTML表单访问PHP文件

[英]Accessing PHP file through HTML form

I am working on my website which having different tabs (home, contact, etc.). 我正在网站上使用不同的选项卡(“主页”,“联系人”等)。 Now in one of these tabs I'm using a login form, in this form I'm just validating one fixed user ( Not Using database ), this will understand from verification.php code. 现在在这些选项卡之一中,我正在使用登录表单,在此表单中,我仅在验证一个固定用户(“ 不使用数据库” ),这可以从verification.php代码中了解。

Below is part of .html file code that calling verification.php file 以下是调用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>

Below is my verification.php file, which is saved by me in www directory, where all the html, css, js files are stored 以下是我的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>

Now the problem is, when I click on the login button, there is nothing happening on the html part. 现在的问题是,当我单击登录按钮时,html部分上没有任何反应。 I mean, my PHP file is not getting access from my HTML part, so please can anyone help me to solve these problem? 我的意思是,我的PHP文件无法从我的HTML部分获得访问权限,所以请有人可以帮助我解决这些问题吗?

I think there's an error in the syntax: first of all there is an additional "T" in the <!DOCTTYPE html> and secondly there's a curly bracket after you started the php script: <?php} , just adding a space will fix your problem. 我认为语法有错误:首先, <!DOCTTYPE html>有一个附加的“ T”,其次,在启动php脚本后出现了花括号: <?php} ,只需添加一个空格即可解决你的问题。

There's also a spelling mistake in your html code regarding the name of the php file verification.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> 

in your verification.php, you can check success/not with using only echo 在您的Verification.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>

This is not how to use PHP, HTML and javascript. 这不是使用PHP,HTML和javascript的方法。 You should start by learning how HTTP works, then HTML, then JavaScript and finally PHP. 您应该首先学习HTTP的工作方式,然后是HTML,然后是JavaScript,最后是PHP。

首先,您应该以html格式正确地编写php文件的名称,即Verification.php Verification.php文件从DOCTTYPE html中删除一个T,并在php和{在PHP {中插入这行之间。

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

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