简体   繁体   中英

php html Why isn't my form showing on the webpage?

I simply cannot understand how and why I am not seeing a form, when opening my site??? I wan a form consisting of bot username, password and a subit box to appear, though I don't see the solution here...

A solution and explaining would be much appreciated.

  <?php
   error_reporting(E_ALL ^ E_NOTICE);
   session_start();
   ?>
<!DOCTYPE html>
<!-- 
-->
   <html>
   <head>
   <meta charset="UTF-8">
   <title>World Talk Login</title>
   </head>
   <body>
   <?php
    $form = "<form action='./login.php' method='post'>
   <table>
   <tr>
   <td>Username:</td>
   <td><input type='text' name='user'/></td>
   </tr>
   <tr>
  <td>Password:</td>
  <td><input type='password' name='password'/></td>
  </tr>
  <tr>
  <td></td>
  <td><input type='submit' name='loginbtn' value='Login'/></td>

  </tr>
  </table>
  </form>";            

  if ($_POST['loginbtn']){
  $user = $_POST ['user'];
  $password = $_POST['password'];

  if ($user) {
  if ($password){
  echo "$user - $password <hr /> $form";
  }
  else
  echo "You must enter your password. $form";
 }
 else
 echo "You must enter your username. $form";
 }
 ?>

</body>
</html>

thanks in advance!

You didn't print your form from PHP or mistakenly wrapped your form in PHP. It was wrapped around the <?php tag in the variable $form but no print to screen.

This is how it should look like below with errors working correctly ;-)

 <?php
   ini_set('display_errors', 1);
   ini_set('display_startup_errors', 1);
   error_reporting(E_ALL);
   session_start();
   ?>
<!DOCTYPE html>
<!--

-->
   <html>
   <head>
   <meta charset="UTF-8">
   <title>World Talk Login</title>
   </head>
   <body>

   <form action='./login.php' method='post'>
   <table>
   <tr>
   <td>Username:</td>
   <td><input type='text' name='user'/></td>
   </tr>
   <tr>
  <td>Password:</td>
  <td><input type='password' name='password'/></td>
  </tr>
  <tr>
  <td></td>
  <td><input type='submit' name='loginbtn' value='Login'/></td>

  </tr>
  </table>
  </form>

<?php

  if ($_POST['loginbtn']){
  $user = $_POST ['user'];
  $password = $_POST['password'];

  if ($user) {
  if ($password){
  echo "$user - $password <hr /> $form";
  }
  else
  echo "You must enter your password. $form";
 }
 else
 echo "You must enter your username. $form";
 }
 ?>

</body>
</html>

您也没有回显您的变量

Try changing your php at the bottom to the following.

if ($_POST['loginbtn']){
    $user = $_POST ['user'];
    $password = $_POST['password'];

    if($user != "" && $password != "") {
        echo "$user - $password <hr /> $form";
    }

    if($user == "") {
        $error .= "You must enter your username.</br>";
    }

    if($password == "") {
        $error .= "You must enter your password.";
    }

    if($error != "") {
        echo $error.$form;
    }
} else {
    echo $form;
}
 <html>
   <head>
   <meta charset="UTF-8">
   <title>World Talk Login</title>
   </head>
   <body>
   <?php
    $form = "<form action='./login.php' method='post'>
   <table>
   <tr>
   <td>Username:</td>
   <td><input type='text' name='user'/></td>
   </tr>
   <tr>
  <td>Password:</td>
  <td><input type='password' name='password'/></td>
  </tr>
  <tr>
  <td></td>
  <td><input type='submit' name='loginbtn' value='Login'/></td>

  </tr>
  </table>
  </form>";

  echo $form;


  if (!isset($_POST['loginbtn'])){
  $user = (!isset($_POST['user']));
  $password = (!isset($_POST['password']));
}
  else{

  }

  ?>

</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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