Rahul waghmare
Rahul waghmare

Reputation: 73

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.

Below is part of .html file code that calling verification.php file

<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

<!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. I mean, my PHP file is not getting access from my HTML part, so please can anyone help me to solve these problem?

Upvotes: 0

Views: 485

Answers (4)

Chandresh Gupta
Chandresh Gupta

Reputation: 9

First of all you should correctly write the name of php file in your html form i.e. verification.php verification.php file remove one T from DOCTTYPE html and give one space between php and { in ?php{ this line.

Upvotes: 0

Bas van Ommen
Bas van Ommen

Reputation: 1293

This is not how to use PHP, HTML and javascript. You should start by learning how HTTP works, then HTML, then JavaScript and finally PHP.

Upvotes: 0

Karan Singh Dhir
Karan Singh Dhir

Reputation: 751

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.

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

Upvotes: 1

Rafid
Rafid

Reputation: 681

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

Upvotes: 0

Related Questions