如何将服务器请求中的值返回到主页并将其用作变量

时间:2016-09-28 15:15:40

标签: php

的login.php

<?php

  //get post data
  $user = trim($_POST['user']);
  $pass = trim($_POST['pass']);
  $nume = $_POST['nume'];
  $class = $_POST['class'];

  // Here I connect to the database and search for $user 
  // if $user is found, i want to:

          alert("succes");   // optional, just a reasurance 
          $name =; // the name of the $user in database
          $class =; // the class of the $user in database 

          // here i want to return the information that i need for main page
          echo $name;
          echo $class;

  ?>

a.html

    <html>
    <head>
    <script type="text/javascript">
         function checkForm(){
            var name = document.forms[0].user.value;
            if (name.length < 3) {
               alert("Username is too short");
               return false;
            } 
            else {  
               return true;
            }
        }
    </script>
    </head>
    <body>
        <form action="login.php" method="POST" onsubmit="return checkForm()">
            User: <input type="text" name="user"/>
            Password: <input type="password" name="pass"/>
            <input type="hidden" name="nume"/>
            <input type="hidden" name="class"/>
            <input type="submit"/>
       </form>
   </body>
   </html>

如何将login.php中的返回值存储在我需要进一步更改主页面的两个变量中? 例如,如何在主页X = $ nume和y = $ class中使用login.php中的值?

0 个答案:

没有答案